akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var T = new string(Str.OrderBy(c => c).ToArray());
		WriteLine(T == "abc" ? "Yes" : "No");
	}
}


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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    e = collections.defaultdict(list)
    for _ in range(n-1):
        b,c = LI_()
        e[b].append(c)
        e[c].append(b)

    if n == 2:
        if a[0] == a[1]:
            return 'YES'
        return 'NO'

    def f(c, p):
        t = []
        ac = a[c]
        for d in e[c]:
            if d == p:
                continue
            r = f(d, c)
            if not r and r != 0:
                return
            t.append(r)

        if not t:
            return ac

        ts = sum(t)
        ma = min(ts//2, ts-max(t))
        at = ts - ac
        if at > ma or at < 0 or at > ac:
            return
        return ac - at

    for i in range(n):
        if len(e[i]) == 1:
            continue
        r = f(i,-1)
        if r == 0:
            return 'YES'
        return 'NO'

    return 'NO'




print(main())






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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

const ll mod = 1e9 + 7;

int main(){
    int n; cin >> n;
    vector<ll> lis(n);
    REP(i, 0, n){cin >> lis[i];}
    ll sum = 0, ans = 0;
    REP(i, 1, n){
        sum += lis[i];
        sum %= mod;
    }
    REP(i, 0, n-1){
        ans += (lis[i] * sum)%mod;
        ans %= mod;
        sum = (sum - lis[i+1] + mod) % mod;
    }
    cout << ans << endl;
}

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

#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)

#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)

#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)

#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))

#define whileZ int T; getI(T); while(T--)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))

#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure

#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int

#define mp make_pair
#define fi first
#define se second

// for debug
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)

#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

ll a[401];
ll dp[401][401][2];     // value of slime, total cost incurred

ll best (int i, int j)  // return minimum cost
{
    if (dp[i][j][1]) return dp[i][j][1];
    if (i==j) {
        dp[i][j][0] = a[i];
        return dp[i][j][1] = 0LL;
    }
    dp[i][j][1] = 99999999999999LL;
    F(jj,i,j) {
        ll temp = best(i,jj) + best(jj+1,j);
        temp += dp[i][jj][0] + dp[jj+1][j][0];
        if (temp <= dp[i][j][1]) {
            dp[i][j][0] = dp[i][jj][0] + dp[jj+1][j][0];
            dp[i][j][1] = temp;    
        }
    }
    return dp[i][j][1];
}

int main()
{
    wez(n);
    F(i,0,n) cin >> a[i];
    cout << best (0,n-1) << "\n";
    return 0;
}

Measured memory_bytes: 2688
#include<stdio.h>

int main(void){
	int a[3];
	int max;
	int i;
	int buff;

	scanf("%d %d %d",&a[0],&a[1],&a[2]);

	for(i=0;i<2;i++){
		if(a[i] > a[i+1]){
			buff = a[i+1];
			a[i+1] = a[i];
			a[i] = buff;
		}
	}
	if(a[0] > a[1]){
		buff = a[1];
		a[1] = a[1];
		a[0] = buff;
	}

	printf("%d\n",a[2] - a[0]);
	return 0;
}

Measured memory_bytes: 128
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.array;

// [0] -> value, [1] -> weight
int[] solve(int[][] items, int limit) {
  int[][] dp = new int[][](items.length + 1, limit + 1);
  int[int] weight;

  for(int i = 0; i < items.length; i++) {
    for(int j = 0; j <= limit; j++) {
      if (j < items[i][1]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        int v = dp[i][j - items[i][1]] + items[i][0];
        if (v > dp[i][j]) {
          dp[i + 1][j] = v;
          if (v in weight) {
            weight[v] = min(weight[v], j);
          } else {
            weight[v] = j;
          }
        } else {
          dp[i + 1][j] = dp[i][j];
        }
      }
    }
  }
  return [dp[items.length][limit], weight[dp[items.length][limit]]];
}

int readnum() {return readln.chomp.to!(int);}

void main() {
  uint index = 1;
  while(true) {
    int limit = readnum;
    if (limit == 0) break;
    int times = readnum;
    int[][] items;
    foreach(t; 0..times) {
      items ~= readln.chomp.split(",").map!(to!(int)).array;
    }
    writeln("Case ", index++, ":");
    solve(items, limit).map!(to!(string)).join("\n").writeln;
  }
}

Measured memory_bytes: 5648
#include <iostream>
#include<algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

int main()
{
	
	long long n,x;
	cin >> n >> x;
	long long ans = 1;
	int b=0;
	int c;
	for (int i = 1; i <= n; i++) {
		cin >> c;
		if (b + c <= x)ans++;
		b = b + c;
	}
	cout << ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const int N = 1e5 + 5;
int in[N];
int s[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", in + i);

    for(int i = 1; i <= n; ++i) {
        s[i] = abs(in[i] - in[i + 1]) + abs(in[i] - in[i - 1]);
    }

    int cost = 0;
    for(int i = 1; i <= n + 1; ++i) cost += abs(in[i] - in[i - 1]);

    for(int i = 1; i <= n; ++i) printf("%d\n", cost - s[i] + abs(in[i - 1] - in[i + 1]));
}

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

int M, N;
int64 w[200001], t[200001];
int c[15], b[15];
int dp[1 << 15];

int main()
{
  cin >> M >> N;
  for(int i = 1; i <= M; i++) {
    cin >> w[i] >> t[i];
    w[i] += w[i - 1];
    t[i] += t[i - 1];
  }
  for(int i = 0; i < N; i++) {
    cin >> c[i] >> b[i];
  }
  dp[0] = 0;
  for(int i = 0; i < 1 << N; i++) {
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) continue;
      int weightHigh = upper_bound(w, w + M + 1, w[dp[i]] + c[j]) - w - 1;
      int widthHigh  = upper_bound(t, t + M + 1, t[dp[i]] + b[j]) - t - 1;
      dp[i|(1 << j)] = max(dp[i|(1 << j)], min(weightHigh, widthHigh));
    }
  }
  cout << *max_element(dp, dp + (1 << N)) << endl;
}

Measured memory_bytes: 4420
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    int ans = 0;
    rep(i, n) rep(j, i + 1, n) rep(k, j + 1, n) {
        if (a[i] < a[j] + a[k] && a[j] < a[k] + a[i] && a[k] < a[i] + a[j] && a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) ++ans;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3660
N, M = map(int, input().split())

S = []
for _ in range(M):
    s = tuple(map(lambda a: int(a) - 1, input().split()))[1:]
    S.append(s)

P = tuple(map(int, input().split()))

ans = 0
for state in range(1 << N):
    for p, s in zip(P, S):
        cnt = 0
        for i in s:
            cnt += 1 if (state & (1 << i)) > 0 else 0
        if cnt % 2 != p:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
n, k = map(int, input().split())

mod = 10 ** 9 + 7

total = 0
for num in range (k, n + 1):
    first = num * (num - 1) // 2 # 最小の整数
    last = (2 * n - num + 1) * num // 2 # 最大の整数
    add = last - first + 1 # 整数の数
    total = (total + add) % mod

print(total + 1)


Measured memory_bytes: 9008
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
		doIt();
	}
	
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		//int[][] d = new int[n][n]; 
		int m = sc.nextInt();
		int[][] road = new int[m][4];
		for(int i = 0; i < m; i++){
			String s = sc.next();
			String[] ss = s.split(",");
			for(int j = 0; j < 4; j++){
				road[i][j] = Integer.parseInt(ss[j]);
			}
		}
		int[] input = new int[4];
		String s = sc.next();
		String[] ss = s.split(",");
		for(int j = 0; j < 4; j++){
			input[j] = Integer.parseInt(ss[j]);
		}
		int start = input[0];
		int goal = input[1];
		//startからgoalの最短距離を求める
		//startからの距離
		int[] d = new int[n];
		Arrays.fill(d, INF);
		d[start - 1] = 0;
		while(true){
			boolean bChange = false;
			//道を見ていく
			for(int i = 0; i < m; i++){
				int from = road[i][0];
				int to = road[i][1];
				int cost = road[i][2];
				if(d[from - 1] != INF && d[from - 1] + cost < d[to - 1]){
					d[to - 1] = d[from - 1] + cost;
					bChange = true;
				}
				
				
				from = road[i][1];
				to = road[i][0];
				cost = road[i][3];
				if(d[from - 1] != INF && d[from - 1] + cost < d[to - 1]){
					d[to - 1] = d[from - 1] + cost;
					bChange = true;
				}
			}
			//print(d);
			if(bChange == false) break;
		}
		int sum = d[goal - 1];
		
		//今度はゴールからスタートまでの最短距離
		start = input[1];
		goal = input[0];
		Arrays.fill(d, INF);
		d[start - 1] = 0;
		while(true){
			boolean bChange = false;
			//道を見ていく
			for(int i = 0; i < m; i++){
				int from = road[i][0];
				int to = road[i][1];
				int cost = road[i][2];
				if(d[from - 1] != INF && d[from - 1] + cost < d[to - 1]){
					d[to - 1] = d[from - 1] + cost;
					bChange = true;
				}
				
				
				from = road[i][1];
				to = road[i][0];
				cost = road[i][3];
				if(d[from - 1] != INF && d[from - 1] + cost < d[to - 1]){
					d[to - 1] = d[from - 1] + cost;
					bChange = true;
				}
			}
			//print(d);
			if(bChange == false) break;
		}
		//System.out.println(d[goal - 1]);
		sum += d[goal - 1];
		
		System.out.println(input[2] - input[3] - sum);
		
	}
	
	public static void print(int[] d){
		for(int a : d){
			System.out.print(a + " ");
		}
		System.out.println();
	}

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,M,V,L;
vector<ll> A;

bool ok(ll X){
	ll mx=A[X]+M;
	ll upcnt=0;
	rep(i,N){
		if(i==X)continue;
		if(A[i]>mx)upcnt++;
	}
	//dbg(upcnt);
	if(upcnt>=L)return false;
	ll rest=V-1-upcnt;
	if(rest<=0)return true;
	//dbg(rest); dbg(mx);
	ll restsum=rest*M;
	//dbg(restsum);
	for(ll i=N-1;i>=0;i--){
		if(i==X)continue;
		if(A[i]<=mx){
			if(upcnt+1<L){
				restsum-=M;
				upcnt++;
			}else{
				restsum-=min(M,mx-A[i]);
			}
		}
	}
	if(restsum<=0)return true;
	else return false;
}

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

  cin>>N>>M>>V>>L;
  A.resize(N);
  rep(i,N)cin>>A[i];
  sort(all(A));
  /*rep(i,N){
  	cout<<A[i]<<" ";
  }
  cout<<endl;*/

  ll lb=-1,ub=N;
  while(ub-lb>1){
  	ll mid=(lb+ub)/2;
  	if(ok(mid)) ub=mid;
  	else lb=mid;
  }
  cout<<N-ub<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int t_before= 0,x_before=0,y_before=0;
    int t,x,y;
    int i;
    int x_diff,y_diff;
    for(i = 0;i < N;i++){
      cin >> t >> x >> y;
      x_diff = abs(x - x_before);
      y_diff = abs(y - y_before);

      if(x_diff+y_diff > t){
        cout << "No" << endl;
        return 0;
      }
      else if(x_diff+y_diff < t){
        if((t - (x_diff+y_diff)) % 2 != 0){
            cout << "No" << endl;
            return 0;
        }
      }
    }
      cout << "Yes" << endl;
      return 0;
}


Measured memory_bytes: 256
er = ["dreamer", "eraser"]
noter = ["dream", "erase"]
words = er + noter
s = input()
while len(s) > 0:
  flag = True
  for word in words:
    if s.endswith(word):
      s = s[:-len(word)]
      flag = False
  if flag:
    print("NO")
    exit()
print("YES")

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a) for (int i = (a); i >= 0; --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int a, b, c, d;

signed main() {
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/


/****** define variable start ******/
ll n, k;
vl p;
/******* define variable end *******/

ll solve(){
    cin >> n >> k;
    p.resize(n);
    REP(i, n){
        cin >> p[i];
    }
    vl sum(n+1);
    REP(i, n){
        sum[i+1] = sum[i]+p[i];
    }
    ll summax = 0;
    REP(i, n-k+1){
        if(sum[i+k] - sum[i] > summax){
            summax = sum[i+k] - sum[i];
        }
    }
    long double ans = (summax+k)/2.0;
    cout << ans << endl;
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;cin>>s;
    bool flag=true;
    int N=s.size();
    int k=N-1;
    for(int i=0;i<N;i++){
        if(s.at(i)!=s.at(k)){
            flag=false;
            break;
        }
        k--;
    }
    int n=(N-1)/2;
    k=n-1;
    for(int i=0;i<n;i++){
        
        if(s.at(i)!=s.at(k)){
            flag=false;
            break;
        }
        k--;
    }
    n=(N+3)/2;
    k=N-1;
    for(int i=n-1;i<N;i++){
        if(s.at(i)!=s.at(k)){
            flag=false;
            break;
        }
        k--;
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3612
import java.util.Scanner;
import java.util.Formatter;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        
        System.out.println(a/b+" "+a%b+" "+String.format("%.5f", 1.0*a/b));
    }
}


Measured memory_bytes: 26564
#include<stdio.h>
#include<string.h>
int main(void){
    int N,i,k,cou;
    char A[100],B[100],C[100];
    scanf("%d",&N);
    scanf("%s",A);
    scanf("%s",B);
    scanf("%s",C);

for(i=0;i<N;i++){
    k=0;
    if(A[i]==B[i]){
        k++;
    }
    if(A[i]==C[i]){
        k++;
    }
    if(B[i]==C[i]){
        k++;
    }

    if(k==1){
        cou+=1;
    }else if(k==0){
        cou+=2;
    }
}


printf("%d",cou);


    return 0;
}

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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N; long K;
    scan(N, K);
    auto A = readln.split.to!(long[]).sort();

    long ng = -infl, ok = infl;

    bool check(long mid) {
        long cnt;
        foreach (i ; 0 .. N) {
            if (A[i] > 0) {
                auto d = mid / A[i];
                if (mid < 0 && mid % A[i] != 0) d--;
                cnt += A[i + 1 .. $].lowerBound(d + 1).length;
            }
            else if (A[i] < 0) {
                auto d = mid / A[i];
                if (mid < 0 && mid % A[i] != 0) d++;
                cnt += A[i + 1 .. $].upperBound(d - 1).length;
            }
            else { // A[i] == 0
                cnt += mid >= 0 ? N - 1 - i : 0;
            }
        }
        debug {
            writefln("%s: %s", mid, cnt);
        }
        return cnt >= K;
    }

    while (abs(ok - ng) > 1) {
        auto mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }

    writeln(ok);
}



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

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 12592
#include <stdio.h>
#define Ns 100000
#define Nt 50000

int main(){
  
  int n, q, i;
  int S[Ns], T[Nt];
  int left, right, mid, key, count=0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &T[i]);
  }

  //left=0; right=n; 
  for(i=0; i<q; i++){
    left=0; right=n; 
    key=T[i];         //printf("key=%d  ", key);
    
    while(left<right){
      mid=(left+right)/2;    //printf("S[mid]=%d\n",S[mid]); 
      if(S[mid]==key) {
	count++;
	//printf("count++\n");
	break;
      }
      if(S[mid]<key){
	left=mid+1;
      }
      if(S[mid]>key){
	right=mid;
	
      }
    }
      
  }

  printf("%d\n", count);
  return 0;
    
}



Measured memory_bytes: 2308
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	int m1,d1,m2,d2;
   	cin >> m1 >> d1;
   	cin >> m2 >> d2;
   	if(m1==m2) cout << 0;
   	else cout << 1;
   	cout << "\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.math.*;

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

        int x;
        int y;

        int a = 0;
        int b = 0;
        int c = 0;
 
        while(sc.hasNext()){
 
            x = sc.nextInt();
            y = sc.nextInt();

            a = x;
            b = y;

            while(a != b){
                if(a >= b){
                    c = a;
                    a = b;
                    b = c - b;
                }else{
                    b = b - a;
                }
            }
            System.out.print(a);
            System.out.print(" ");
            System.out.println((x/a)*y); 
        }
    }
}

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

#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector < ll >
#define vvll vector < vll >
#define vld vector < ld >
#define pll pair < ll,ll > 
#define ppll pair < ll, pll>
#define pld pair < ld,ld > 
#define vpll vector < pll >
#define vpld vector < pld >
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
vll emptyVector;
const ll MAX = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll binaryExpo(ll x, ll n)
{
	if(n == 0)
		return 1;
	if(n % 2 == 0)
		return binaryExpo((x*x), n/2);
	return (x*binaryExpo((x*x), n/2));
}
const double pi = 3.141592653589793238462643383279502884197169399375105;
/*-------------------------------------------		CODE STARTS FROM HERE		------------------------------------------*/



void solve(void)
{
	int n, m;
	cin >> n >> m;
	vector < int > adj[MAX];
	bool vis[n + 1];
	int dis[n + 1], ans[n + 1];
	for(int i = 0; i <= n; i++)
	{
		vis[i] = false;
		dis[i] = -1;
		ans[i] = -1;
	}

	dis[1] = 0;

	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	priority_queue < pll, vector < pll >, greater < pll > > pq;

	pq.push(mp(0, 1));
	while(!pq.empty())
	{
		pll tmp = pq.top();
		pq.pop();
		if(!vis[tmp.ss])
		{
			vis[tmp.ss] = true;
			dis[tmp.ss] = tmp.ff;
			for(int i = 0; i < adj[tmp.ss].size(); i++)
			{
				if(!vis[adj[tmp.ss][i]])
				{
					if(ans[adj[tmp.ss][i]] == -1)
						ans[adj[tmp.ss][i]] = tmp.ss;
					
					pq.push(mp(tmp.ff + 1, adj[tmp.ss][i]));
				}
			}
		}
	}

	for(int i = 1; i <= n; i++)
	{
		if(dis[i] == -1)
		{
			cout << "No" << endl;
			return ;
		}
	}

	cout << "Yes" << endl;
	for(int i = 2; i < n + 1; i++)
		cout << ans[i] << endl;



}


int main(void)
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	// int t;
	// cin >> t;
	// while(t--)
	{
		solve();
	}
	




	return 0;
}

Measured memory_bytes: 15036
#include <stdio.h>

int main(){
int n,k,i,j,p,q,a[200],b[200][200];

scanf("%d",&n);

for(k=0;k<n;k++){
scanf("%d",&a[k]);
scanf("%d",&a[k+1]);
}

for(k=1;k<=n;k++)
b[k][k]=0;

for(j=2;j<=n;j++){
for(i=1;i<=n-j+1;i++){
p=i+j-1;
b[i][p]=10000000;

for(k=i;k<=p-1; k++){
q=b[i][k]+b[k+1][p]+a[i-1]*a[k]*a[p];
if(b[i][p]>=q)
b[i][p]=q;
}

}
}

printf("%d\n",b[1][n]);
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  
  int n = 0;
  int s = 0;
  int e = 0;
  int w = 0;
  
  for(int j=0; j<S.size(); j++){
    if(S.at(j) == 'N'){
      n++;
    }
    if(S.at(j) == 'S'){
      s++;
    }
    if(S.at(j) == 'E'){
      e++;
    }
    if(S.at(j) == 'W'){
      w++;
    }
  }
  string ans = "Yes";
  if(n == 0 && s != 0){
    ans = "No";
  }
  if(n != 0 && s == 0){
    ans = "No";
  }
  if(e == 0 && w != 0){
    ans = "No";
  }
  if(e != 0 && w == 0){
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Scannerクラスのインスタンスを作成
        // 引数で標準入力System.inを指定する
        Scanner scanner = new Scanner(System.in);

        //入力内容をインスタンスから取得。a,bに代入する。
        int a = scanner.nextInt();
        int b = scanner.nextInt();

        System.out.println(a*b + " " + (a*2+b*2));

        scanner.close();
    }
}


Measured memory_bytes: 26132
#include <iostream>
using namespace std;
struct dice{
    int x[6];
    
    void roll(char c){
        int tmp;
        if(c == 'E'){
            tmp = x[0];
            x[0] = x[3];
            x[3] = x[5];
            x[5] = x[2];
            x[2] = tmp;
        }
        if(c == 'N'){
            tmp = x[0];
            x[0] = x[1];
            x[1] = x[5];
            x[5] = x[4];
            x[4] = tmp;
        }
        if(c == 'S'){
            tmp = x[0];
            x[0] = x[4];
            x[4] = x[5];
            x[5] = x[1];
            x[1] = tmp;
        }
        if(c == 'W'){
            tmp = x[0];
            x[0] = x[2];
            x[2] = x[5];
            x[5] = x[3];
            x[3] = tmp;
        }
    }
    int top(){
        return x[0];
    }
};

int main(void){
    dice d;
    for(int i = 0; i < 6; i++){
        cin >> d.x[i];
    }
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        d.roll(s[i]);    
    }
    cout << d.top() << endl;

    return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <stdio.h>
using namespace std;
 
int main(){
    static const double pi = 3.14159265358979323846;
    int A, B, H, M;
    cin>> A>>B>>H>>M;
    double angle1 = 2*pi*H/12.0 + 2*pi/12.0*M/60.0;
    double angle2 = 2*pi*M/60.0;

    double x1 = A*cos(angle1);
    double y1 = A*sin(angle1);
    double x2 = B*cos(angle2);
    double y2 = B*sin(angle2);

    double  dist = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    //cout << dist<<endl;
    printf("%.20lf",dist);
    return 0;
}

Measured memory_bytes: 4064
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef std::pair<int,int> P;
#define mk std::make_pair
#define fr first
#define sc second
inline int in()
{
	int k=0;char ch=gt;bool p=1;
	while(ch<'-')ch=gt;if(ch=='-')ch=gt,p=0;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return p?k:-k;
}
const int N=105;
int f[N][N],d[N][N];
int main()
{
	int n=in(),m=in();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			d[i][j]=in();
	for(int i=0;i<=100;++i)
		for(int j=0;j<=100;++j)
			for(int a=1;a<=n;++a)
				for(int b=1;b<=m;++b)
					f[i][j]=std::max(f[i][j],d[a][b]-a*i-b*j);
	for(int a=1;a<=n;++a)
		for(int b=1;b<=m;++b)
		{
			int mi=1e9;
			for(int i=0;i<=100;++i)
				for(int j=0;j<=100;++j)
					mi=std::min(mi,f[i][j]+a*i+b*j);
			if(mi!=d[a][b])return puts("Impossible"),0;
		}
	puts("Possible\n202 10401");
	for(int i=1;i<=100;++i)printf("%d %d X\n",i,i+1);
	for(int i=1;i<=100;++i)printf("%d %d Y\n",i+101,i+102);
	for(int i=0;i<=100;++i)
		for(int j=0;j<=100;++j)
			printf("%d %d %d\n",i+1,202-j,f[i][j]);
	puts("1 202");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	char X,Y; cin>>X>>Y;
	ote(X==Y?"=": X<Y? "<":">");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXN 2000100
#define ll long long
#define inf 1000000000
ll n, m, a[MAXN], t, mod = 1000000007, k, sum[MAXN], ans;
int main()
{
	scanf("%lld%lld",&n,&k);
	n++;
	for(ll i=1;i<=n;i++)
		a[i] = i-1;
	for(ll i=1;i<=n;i++) sum[i] = sum[i-1] + a[i];
	for(ll i=k;i<=n;i++)
	{
		t = sum[n] - sum[n-i] - sum[i] + 1;
//cout<<t<<endl;
		ans = (ans + t) % mod;
	}
	printf("%lld\n",ans);
	
	return 0;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;

    if(a == b && b == c && a == c) {
        //three same
        cout << "No";
    }else if(a == b || b == c || a == c){
        //two same
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

int main(){
	int n;
	int i , j , k , l;
	int cnt=0;
	while(cin>>n){
		for(i=0 ; i<10 ; i++){
			for(j=0 ; j<10 ; j++){
				for(k=0 ; k<10 ; k++){
					for(l=0 ; l<10 ; l++){
						if(i+j+k+l==n){
							cnt++;
						}
					}
				}
			}
		}
		cout << cnt << endl;
                cnt=0;
	}
	return 0;
}

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

using namespace std;

int main(){
	string n; cin >> n;
	for(int i = 0; i < n.size(); ++i){
		if(n[i] == '1') n[i] = '9';
		else if(n[i] == '9') n[i] = '1';
	}
	cout << n << endl;
}

Measured memory_bytes: 256
n = int(input())
abc = []
for _ in range(3):
    abc.append(str(input()))
cnt = 0
for i in range(n):
    if abc[0][i]==abc[1][i]==abc[2][i]:
        cnt += 0
    elif (abc[0][i]==abc[1][i]!=abc[2][i])\
        or (abc[1][i]==abc[2][i]!=abc[0][i])\
        or (abc[2][i]==abc[0][i]!=abc[1][i]):
        cnt += 1
    else:
        cnt += 2
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int ans = 0;
    for( int i = 0; i < s.size(); ++i ) {
        int j = i;
        int cnt = 0;
        bool flg = true;
        while( j < s.size() && flg ) {
            if( s[j] != 'A' && s[j] != 'T' && s[j] != 'C' && s[j] != 'G' ) {
                flg = false;

            } else ++cnt;
            ++j;

        }
        ans = max( ans, cnt );
    }

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


Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
const int MAXN = 2e3+55;
int vis[20];
int main()
{
    int n,k,v;
    cin>>n>>k;
    for(int i=1;i<=k;++i)
    {
        cin>>v;
        vis[v]++;
    }
    string s;
    for(int i = n;;++i)
    {
        stringstream in;
        in<<i;
        in>>s;
        bool flag = true;
        for(int i=0;i<s.size();++i)
        {
            int t = s[i] - '0';
            if(vis[t]){
                flag = false;
                break;
            }
        }
        if(flag) {cout<<i;return 0;}
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int a[n+1];
    int i;
    int position1;
    for(i=1;i<=n;i++){
        scanf("%d", &a[i]);
        if(a[i]==1) position1 = i;
    }
    int len = 0;
    len += (position1-1)+(n-position1);
    
    if(len%(k-1)==0) printf("%d", len/(k-1));
    else printf("%d", len/(k-1)+1);
    
    return 0;
}

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

int main() {
  long long a,b;
  cin>>a>>b;
  while(a!=b){
    if(a%b==0||b%a==0){
      a=min(a,b);
      b=a;
    }
    else if(a>b)a%=b;
    else b%=a;
  }
  long long ans=0;
  for(int i=2;i<sqrt(a)+1;i++){
    if(a%i==0){
      ans++;
      while(a%i==0)a/=i;
    }
  }
  if(a!=1)ans++;
  cout<<ans+1<<endl;
}


Measured memory_bytes: 256
package main

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

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

	s := nextString(sc)
	n := nextInt(sc)
	for i := int64(0); i < n; i++ {
		o := nextString(sc)
		switch o {
		case "print":
			fmt.Println(s[nextInt(sc) : nextInt(sc)+1])
		case "reverse":
			p1 := nextInt(sc)
			p2 := nextInt(sc)
			for p1 < p2 {
				c1 := s[p1]
				t := s[:p1] + string(s[p2]) + s[p1+1:p2] + string(c1)
				if p2+1 <= int64(len(s))-1 {
					t += s[p2+1:]
				}
				s = t
				p1++
				p2--
			}
		case "replace":
			p1 := nextInt(sc)
			p2 := nextInt(sc)
			c := nextString(sc)
			t := s[:p1] + c
			if p2+1 <= int64(len(s))-1 {
				t += s[p2+1:]
			}
			s = t
		}
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 5868
#include <iostream>
#include <algorithm>
using namespace std;
long long a, b, c, d, l;

int main() {
	cin>>a>>b>>c>>d;
	a--;
	l = c / __gcd(c, d) * d;
	cout<<b - b/c - b/d + b/l - (a - a/c - a/d + a/l);
	return 0;
}

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

class Dice{
public:
  int face[6];
  Dice(){}

  void roll_x(){ roll(0,3,5,2);}
  void roll_y(){ roll(0,1,5,4);}
  void roll_z(){ roll(1,2,4,3);}
  void roll(int i, int j, int k, int l){
    int t = face[i]; face[i] = face[j]; face[j] = face[k]; face[k] = face[l]; face[l] = t;
  }
};

bool check(Dice d1,Dice d2){
  for (int i = 0; i < 6; i++){
    if (d1.face[i] != d2.face[i]) return false;
  }
  return true;
}

bool rotation(Dice d1, Dice d2){
  for(int j = 0; j < 6; j++){
    for(int k = 0; k < 4; k++){
      if(check(d1, d2)) return true;
      d1.roll_z();
    }

    if(check(d1,d2)) return true;
    if (j == 2) d1.roll_y();
    else d1.roll_x();
  }
  return false;
}

int main(){
  Dice d1,d2;
  for(int i = 0; i < 6; i++){
    cin >> d1.face[i];
  }
  for(int i = 0; i < 6; i++){
    cin >> d2.face[i];
  }

  if ( rotation(d1, d2)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

int main() {
  int N;
  cin >> N;
  if (N == 7 || N == 5 || N == 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), P, M;
    ll count_plus = 0, count_minus = 0, count_zero = 0;
    rep(i,N) {
        cin >> A[i];
        if (A[i] > 0) {
            count_plus++;
            P.push_back(A[i]);
        }
        else if (A[i] < 0) {
            count_minus++;
            M.push_back(A[i]);
        }
        else count_zero++;
    }

    sort(P.begin(), P.end());
    sort(M.begin(), M.end());
    
    ll prod_plus = count_plus * (count_plus - 1) / 2 + count_minus * (count_minus - 1) / 2;
    ll prod_minus = count_plus * count_minus;
    ll prod_zero = N * (N - 1) / 2 - prod_plus - prod_minus;
    if (K > prod_minus && K <= prod_minus + prod_zero) {
        cout << 0 << endl;
    } else if (K > prod_minus + prod_zero) {
        K -= prod_minus + prod_zero;
        ll bottom = 0;
        ll top = LINF;
        sort(M.begin(), M.end(), greater<ll>());
        while (bottom < top) {
            ll x = bottom + (top - bottom) / 2;
            ll sum = 0;
            int j;
            // x 以下を数えていく
            j = -1;
            for (int i = count_plus - 1; i >= 0; i--) {
                while (j + 1 < count_plus && P[i] * P[j + 1] <= x) j++;
                sum += j + 1;
                if (P[i] * P[i] <= x) sum--;
            }
            j = -1;
            for (int i = count_minus - 1; i >= 0; i--) {
                while (j + 1 < count_minus && M[i] * M[j + 1] <= x) j++;
                sum += j + 1;
                if (M[i] * M[i] <= x) sum--;
            }
            sum /= 2;
            if (sum >= K) top = x;
            else bottom = x + 1;
        }
        cout << bottom << endl;

    } else {
        ll top = P[0] * M[count_minus - 1];
        ll bottom = P[count_plus - 1] * M[0];
        while (bottom < top) {
            ll x = bottom + (top - bottom) / 2;
            ll sum = 0;
            int i = 0, j = 0;
            while (i < count_minus && j < count_plus) {
                if (M[i] * P[j] > x) {
                    if (j < count_plus - 1) j++;
                    else i++;
                }
                else {
                    sum += count_plus - j;
                    i++;
                }
            }
            // x 以下を数えていく
            if (sum >= K) top = x;
            else bottom = x + 1;
        }
        cout << bottom << endl;
    }

    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    ll total = 0;
    ll l,r;
    for(size_t i=0;i<N; i++)
    {
        cin >> l >> r;
        total += (r-l)+1;
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long int ll;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int n;
  int a[300000];
  cin >> n;
  for (int i=0; i<n*3; ++i) cin >> a[i];
  sort(a, a+(n*3), greater<int>());

  ll ans = 0;
  for (int i=0; i<n; ++i) {
    ans += a[i*2+1];
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1408
//#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int & 
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<class T>
void show(const vector<T> &a) {
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int N = 1e5 + 9;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#define int ll 
	
	int n;
	cin >> n;
	vi a(n);
	fori(i, n) {
		cin >> a[i];
		a[i] *= 2;
	}
	sort(ALL(a));
	int dist = 2e9;
	int sec = -1;
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] == a[n - 1]) break;
		int cur = abs(a[n - 1] / 2 - a[i]);
		if (cur < dist) {
			dist = cur;
			sec = a[i];
		}
	}
	cout << a[n - 1] / 2 << " " << sec / 2 << endl;

}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int ans;

void soi(int k,int n) {
  if(k != 1) {
    for(int i=0;i<10;i++) {
      soi(k-1,n-i);
    }
  }
  else if((k == 1) &&(n <= 9 && n >= 0)){
    ans++;
      }
}



  int main() {
    int x;
    while(cin >> x) {
      soi(4,x);
      cout << ans << endl;
      ans = 0;
    }
  }

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

/*
 貪欲
 ①決定問題 必ず解に含まれる(含むように変換できる)ものから決めていく みんプロ本選B
 ②最適化問題 任意の解から評価を落とさず解に含められるようなものから決めていく 区間スケジューリングとか
 ③
 */

/*
 DP
 ①DPはある程度決め打ちをするべき(解を帰納的に構成できないか？)
 */

ll gcd(ll a, ll b) {		// ユークリッドの互除法
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll gcddesu=a[0];
	ll maxi=a[0];
	FOR(i,1,n) {
		gcddesu=gcd(gcddesu,a[i]);
		maxi=max(maxi,a[i]);
	}
	if(k%gcddesu==0&&k<=maxi) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int maxd = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            maxd = max(maxd, abs(A[i] - A[j]));
        }
    }
    cout << maxd << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
B1 = [A[i]+i for i in range(N)]
B2 = [-A[i]+i for i in range(N)]

C1 = Counter(B1)
C2 = Counter(B2)
ans = 0
for i in C1:
    if i in C2:
        ans += C1[i]*C2[i]
print(ans)

Measured memory_bytes: 63344
N = int(input())
S = []
for i in range(N):
    S.append(input())

alfa = [chr(i) for i in range(97,97+26)]
counter = [1000000 for i in range(26)]

for s in S:
    for i in range(26):
        counter[i] = min(s.count(alfa[i]), counter[i])

ans = ''
for i in range(26):
    for j in range(counter[i]):
        ans += alfa[i]

print(ans)

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

#define MAX_HW 100

int H, W;
int N;
int a[MAX_HW * MAX_HW];

int p[MAX_HW][MAX_HW];

int main()
{
	cin >> H >> W >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	int flag = 0;
	int pos = 0;
	int h = 0;
	int w = 0;
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < a[i]; j++ ) {
			p[h][w] = i + 1;
			pos++;
			if( pos < W ) {
				if( flag == 0 ) {
					w++;
				}
				else {
					w--;
				}
			}
			else {
				pos = 0;
				h++;
				if( flag == 0 ) {
					w = W - 1;
				}
				else {
					w = 0;
				}
				flag = 1 - flag;
			}
		}
	}

	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			cout << p[i][j];
			if( j < W - 1 ) {
				cout << " ";
			}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (K, Q) = readLine()!!.split(" ").map(String::toInt)
    val D = readLine()!!.split(" ").map(String::toInt)
    fun divceil(a: Long, b: Int) = (a + b - 1) / b
    for (i in 1..Q) {
        val (N, X, M) = readLine()!!.split(" ").map(String::toLong)
        var Xn = X
        var eq = 0L
        for (j in 0 until K) {
            val num = divceil(N - j - 1, K)
            Xn += (D[j] % M) * num
            if (D[j] % M == 0L) eq += num
        }
        println((N - 1) - (Xn / M - X / M) - eq)
    }
}

Measured memory_bytes: 43076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int s_1=a/100;
  int s_2=(a-(s_1*100))/10;
  int s_3=a-s_1*100-s_2*10;
  cout << s_1+s_2+s_3 << endl;
}

Measured memory_bytes: 256
str=STDIN.gets.split(" ")
nums=[]
str.each{|st|
 nums.push st.to_i
}
w,h,x,y,r=nums
if ((x+r<=w)&&(y+r<=h))&&((x-r>=0)&&(y-r>=0))
 puts("Yes")
else
 puts("No")
end

Measured memory_bytes: 8608