akhauriyash/Code-Regression huggingface dataset:
import collections as coll
import bisect
n,m=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(m)]
a=coll.defaultdict(list)
for x,y in sorted(py): a[x].append(y)
for x,y in py:
    z=bisect.bisect(a[x],y)
    print('%06d%06d'%(x,z))

Measured memory_bytes: 43328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()){
        cout<<"GREATER"<<endl;
        return 0;
    }
    else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
        return 0;
    }
    else{
        for(int i=0;i<a.size();i++){
            if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }
            else if(a[i]<b[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
        }
    }
    cout<<"EQUAL"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
// using System.Math;
class Program
{
  static void Main(string[] args)
  {
    // スペース区切りの整数の入力
    int a,b,c;
    string[] input = Console.ReadLine().Split(' ');
    a  = int.Parse(input[0]);
    b  = int.Parse(input[1]);
    c  = int.Parse(input[2]);

    int max;
    max = Math.Max(a,b);
    max = Math.Max(max,c);

    int count=0;
    for (int i=0;i<100;i++){
      if (a < max-1){
        a+=2;
        count++;
      }
    }
    for (int i=0;i<100;i++){
      if (b < max-1){
        b+=2;
        count++;
      }
    }
    for (int i=0;i<100;i++){
      if (c < max-1){
        c+=2;
        count++;
      }
    }

    int maxnoteq=0;
    if (a!=max)maxnoteq++;
    if (b!=max)maxnoteq++;
    if (c!=max)maxnoteq++;

    if (maxnoteq==1)count+=2;
    if (maxnoteq==2)count++;


    Console.WriteLine(count);

  }


}

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

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

int main() {
    int N, ans = 0;
    cin >> N;

    for (int i = 1; i <= N; i += 2) {
        int y = 0;
        for (int j = 1; j <= i; j += 2)
            if (i % j == 0)
                y++;
        if (y == 8)
            ans++;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

	FAST;

	char x;
	string ans = "";
	for (int i = 0; i < 9; i ++) {
		cin >> x;
		if (i == 0) {
			ans += x;
		}
		if (i == 4) {
			ans += x;
		}
		if (i == 8) {
			ans += x;
		}
	}
	cout << ans << '\n';
	return 0;
}

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

void solve(std::string S, std::string T) {
  ll ans = S.size();
  REP(i, S.size() - T.size() + 1) {
    ll count = 0;
    REP(j, T.size()) {
      if (S[i + j] != T[j]) {
        count++;
      }
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}


Measured memory_bytes: 3628
import bisect

a, b, q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for _ in range(a)] + [INF]
t = [-INF] + [int(input()) for _ in range(b)] + [INF]
x = [int(input()) for _ in range(q)]

for i in x:
    si = bisect.bisect_left(s, i)
    ti = bisect.bisect_left(t, i)
    sl, sr = i-s[si-1], s[si]-i
    tl, tr = i-t[ti-1], t[ti]-i
    print(min(max(sl,tl), sl+tr+min(sl,tr), sr+tl+min(sr,tl), max(sr,tr)))

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

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z <<' ' << X << ' ' <<  Y << endl;
  
  return 0;
}




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

typedef long long ll;

int main(){
    ll q,h,s,d;
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;

    q *= 4;
    h *= 2;
    ll ans = 0;

    if(n%2 == 1){
        ans += min({q,h,s});
    }
    ans += min({q*2,h*2,s*2,d})*(n/2);
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b)
{
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    vector<pair<ll, ll>> island(M);
    for (int i = 0; i < M; i++)
    {
        ll m, n;
        cin >> m >> n;
        island[i] = make_pair(n, m);
    }
    SORT(island);

    ll last = -1;
    ll ans = 0;
    for (int i = 0; i < M; i++)
    {
        if (last <= island[i].second)
        {
            last = island[i].first;
            ans++;
        }

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


Measured memory_bytes: 1792
#![allow(non_snake_case)]

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let N : isize = buf.trim().parse().unwrap();

    let mut A : Vec<isize> = Vec::new();
    buf.clear();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    for _ in 0..N {
        A.push(iter.next().unwrap().parse().unwrap());
    }
    for (i, a) in A.iter().rev().enumerate() {
        print!("{}", *a);
        if i < A.len() - 1 {
            print!(" ");
        }
    }
    println!();
}



Measured memory_bytes: 5032
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














double R;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> R;
	double ans = 2 * R * 3.14;
	printf("%.5f\n", ans);
}







Measured memory_bytes: 3804
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        if (a == b && a == c && b == c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
a, b, c, d, e, f = map(int, input().split())

maxn = .0
total, sato = 0, 0
for _a in range(0, f+1, 100*a):
  for _b in range(0, f-_a+1, 100*b):
    if _a == 0 and _b == 0:
      continue
    for _c in range(0, f-_a-_b+1, c):
      for _d in range(0, f-_a-_b-_c+1, d):
        if ((_a + _b) // 100) * e < _c + _d:
          break
        if 100 * (_c + _d) / (_a + _b + _c + _d) >= maxn:
          maxn = 100 * (_c + _d) / (_a + _b + _c + _d)
          total = _a + _b + _c + _d
          sato = _c + _d
print(total, sato)


Measured memory_bytes: 43756
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, k;
string s;
vector<P> a;
vector<int> v;

int32_t main(){_

   cin>>n>>k;
   cin>>s;

   int cnt = 0,  j = 0;
   for (int i = 0; i < n; i = j)
   {
      j = i, cnt = 0;
      while(j < n and s[i] == s[j]){
         cnt++;
         ++j;
      }
      int add = 0;
      if(!a.empty())add = a.back().S;
      a.pb({s[i]-'0', add+cnt});
   }

   // cout<<"ccc";

   n = sz(a);
   for (int i = 0; i < sz(a); ++i)
   {
      if(a[i].F == 0){
         if(v.empty())v.pb(1);
         else v.pb(v.back() + 1);
      }
      else{
         if(v.empty())v.pb(0);
         else v.pb(v.back());
      }
   }

   int ans = 0;   
   for (int i = 0; i < n; ++i)
   {
      if(a[i].F == 0){
         int it = upper_bound(v.begin(), v.end(), v[i]+k-1) - v.begin();
         --it;
         int sub = (i-1 < 0) ? 0 : a[i-1].S;
         tr(i, it, a[it].S, sub);
         smax(ans, a[it].S - sub);
      }
      else{
         int it = upper_bound(v.begin(), v.end(), v[i]+k) - v.begin();
         --it;
         int sub = (i-1 < 0) ? 0 : a[i-1].S;
         tr(i, it, a[it].S, sub);
         smax(ans, a[it].S - sub);
      }
   }

   cout<<ans;
   return 0;
}

// Common sense: do smth instead of nothing

Measured memory_bytes: 3776
n=int(input())
A=[input() for i in range(n)]
ac=0
wa=0
tle=0
re=0
for i in range(n):
    if A[i]=="AC":
        ac+=1
    elif A[i]=="WA":
        wa+=1
    elif A[i]=="TLE":
        tle+=1
    else:
        re+=1
s=[ac,wa,tle,re]
h=["AC","WA","TLE","RE"]
for i in range(4):
    print(h[i]+" x "+str(s[i]))

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

class Main {

    public static void main(String[] args) {
       MyScanner sc = new MyScanner();
       int K = sc.nextInt();
       int X = sc.nextInt();

       String ans = "";
       for (int i=0; i<2*K-1; i++){
           ans += X-K+1+i;
           ans += " ";
       }
       System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
    
        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 24660
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> data(1000000,-1);

int root(int x){
    return (data[x] < 0)? x : data[x]=root(data[x]);
}

bool unite(int x, int y){
    x=root(x);
    y=root(y);
    if( x != y ){
        if( data[y] < data[x] ) swap(x, y);
        data[x] += data[y];
        data[y] = x;
    }
    return x!=y;
}

bool find(int x, int y){
    return root(x) == root(y);
}

int size(int x){
    return -data[ root(x) ];
}

int main(){
    int n,m;
    cin>>n>>m;
    rep(i,0,n){
        int k;
        cin>>k;
        rep(j,0,k){
            int l;
            cin>>l;
            unite(i,l+200000);
        }
    }

    rep(i,1,n){
        if(!find(i,i-1)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    long long int N, K, a, f, start = 1, n = 0;
    vector<long long int> A;
    map<long long int, long long int> mp;
    cin >> N >> K;
    n = K;
    for (int i = 0; i < N; i++) {
        cin >> a;
        A.push_back(a);
    }
    int next = A[0];
    int prev = 1;
    for (long long int i = 1; i <= K; i++) {
        if (next != 1 && mp[next] == 0) {
            mp[next] = i;
            prev = next;
        } else {
            f = i - mp[next];
            n = (K - mp[next]) % f;
            start = next;
            break;
        }
        next = A[next-1];
    }
    for (int i = 0; i < n; i++) {
        start = A[start-1];
    }
    cout << start << endl;
    return 0;
}


Measured memory_bytes: 14628
#include <stdio.h>
int main(){
	int a[100], max=0, b=0, c=0;
	scanf("%d",&max);
	for(b = 0; b<max; b++){
		scanf("%d",&a[b]);
	
	}
	for(c = max-1; c>0;c--){
		printf("%d ",a[c]);
	}
	printf("%d",a[0]);
	printf("\n");
	


//	scanf("%d",&max);
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    int alphabets[3] = {0, 0, 0};
    for(int i = 0; i < S.size(); i++){
        alphabets[S[i] - 'a']++;
    }
    sort(alphabets, alphabets + 3);
    if(alphabets[2] - alphabets[0] <= 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

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

    int min = 99999999999999;
    int cnt = 0;
    rep (i, N) {
        int a;
        cin >> a;
        if (a <= min) {
            min = a;
            cnt++;
        }
    }

    cout << cnt << endl;

}



Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;


int main( ) {
      ll n;
      cin>>n;
      ll m;
      cin>>m;
      vector<ll> v(n);
      for(ll i=0;i<n;i++)
        cin>>v[i];
      sort(v.begin(),v.end());

      vector<pair<ll,ll> > pa;
      for(ll i=0;i<m;i++)
      {
        ll x,y;
        cin>>x>>y;
        pa.pb(mp(y,x));
      }
      ll j=0;
      sort(pa.begin(),pa.end());
      reverse(pa.begin(),pa.end());

      for(ll i=0;i<pa.size();i++)
      {
        int cnt=0;
        while(j<n&&v[j]<=pa[i].fi&&cnt<pa[i].se)
        {

          cnt++;
          v[j]=pa[i].fi;
          j++;
        }
        if(j==n||v[j]>pa[i].fi)
          break;

      }
      ll ans=0;
      for(ll i=0;i<n;i++)
        ans+=v[i];
      cout<<ans;
  }


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
    
#define sz(x) (int) (x).size()
#define INF 0x3f3f3f3f
#define pb push_back
    
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
    
const int N = 100005;
const int mod = 1000000007;

vector<int> grafo[N];
vector<int> rec;
bool vis[N], vit[N];

void dfs(int x) {
    vis[x] = true;
    for (int v: grafo[x])
        if (!vis[v]) dfs(v);
    rec.pb(x);
}

int memo[N];

int solve(int x) {
    if (sz(grafo[x]) == 0) return 0;
    if (memo[x] != -1) return memo[x];
    int ans = 0;
    for (int v: grafo[x]) {
        ans = max(ans, 1 + solve(v));
    }
    return memo[x] = ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, a, b;
    cin >> n >> m;
    while (m--) {
        cin >> a >> b;
        grafo[a].pb(b);
    }
    for (int i = 1; i <= n; i++) {
        memo[i] = -1;
        if (!vis[i]) dfs(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (vit[i]) continue;
        vit[i] = true;
        ans = max(ans, solve(i));
    }
    cout << ans << "\n";

    //cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

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

const int MOD = 1e9+7;

int main(){
    int h,w;
    cin>>h>>w;
    vector<string>arr(h+1);
    vector<vector<int>>dp(h+1,vector<int>(w+1));
    for(int i=1; i<=h; i++){
        cin>>arr[i];
    }
    for(int i=0; i<=h||i<=w; i++){
        if(i<=h)dp[i][0]=0;
        if(i<=w)dp[0][i]=0;
    }
    dp[1][1]=1;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(arr[i][j-1]=='.'&&(i!=1||j!=1)){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }else if((i!=1||j!=1)){
                dp[i][j] = 0;
            }
        }
    }

    cout<<dp[h][w];
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	bool c=false;
	int a;
	int r[4]={10,50,100,500};
	while(cin>>a,a){
		if(c)cout<<endl;
		c=true;
		
		int co=0;
		vi in(4);
		
		rep(i,4){cin>>in[i];co+=in[i];}
		int mi=1e9;
		vi out(4);
		rep(i,in[0]+1)rep(j,in[1]+1)rep(k,in[2]+1)rep(w,in[3]+1){
			//
			int cnt=co-i-j-k-w;
			int dai=10*i+50*j+100*k+500*w;
			if(dai<a)continue;
			int turi=dai-a;
			rep(q,4)while(turi>=r[3-q]){cnt++;turi-=r[3-q];}
			//
			if(cnt<mi){
				mi=cnt;
				out[0]=i;out[1]=j;out[2]=k;out[3]=w;
			}
		}
		rep(i,4)if(out[i])cout<<r[i]<<" "<<out[i]<<endl;
	}
}

Measured memory_bytes: 1196
import sys
input() # no use
lst = list(map(int, input().split()))
# print(lst)
# すべて同じ数の場合は 0 or 1
if len(lst) == 1 or set(lst) == 1:
    if lst[0] == 0:
        print(0)
    else:
        print(1)
    sys.exit()
   
# 同じ数字の並びは不要なため削除する
tmp = []
prev = -1
for now in lst:
    if now != prev:
        tmp += [now]
        prev = now
lst = tmp

# 両端が０でない場合、0を追加
if lst[0] != 0:
    lst = [0] + lst
if lst[-1] != 0:
    lst = lst + [0]

# 頂点と底以外は不要なため削除する
tmp = []
for i in range(1, len(lst) -1):
    prev = lst[i-1]
    now = lst[i]
    next = lst[i+1]
    if prev < now and now < next:
        continue # 右上がりの途中
    if prev > now and now > next:
        continue # 右下がりの途中
    tmp += [now]

lst = tmp

# この時点で以下のようなリストになる
# 島海島(奇数) or 島海島海(偶数)

top = lst[0::2]
bot = lst[1::2]

# top.sort(reverse=True)
# bot.sort(reverse=True)
top.sort()
bot.sort()

# 両端に0を追加
lst = [0] + lst + [0]

# print(top, bot, lst)

jpHeightList = lst
seaHeightList = set(jpHeightList)
maxCount = 0

topLen = len(top)
botLen = len(bot)
topNext = 0
botNext = 0

# 島の数＝海面上の頂点ー海面上の底面の最大値を求める
for i, seaHeight in enumerate(sorted(list(seaHeightList))):
    # 海面上の頂点
    # topCount = topLen - i -1
    # topCount = sum(list(map(lambda x:1 if x-seaHeight>0 else 0, top)))
    for j in range(topNext, topLen): # 一回沈んだ底はみなくてよい
        if top[j] > seaHeight:
            topNext = j  # j → 沈んだ島の数。
            break
        elif j == topLen -1:
            topNext = topLen
    topCount = topLen - topNext 
    
    # 海面上の底面 
    for j in range(botNext, botLen): # 一回沈んだ底はみなくてよい
        if bot[j] > seaHeight:
            botNext = j  # j → 沈んだ島の数。
            break
        elif j == botLen -1:
            botNext = botLen
    botCount = botLen - botNext 

    tmpCount = topCount - botCount
    if tmpCount > maxCount:
        maxCount = tmpCount

print(maxCount)




Measured memory_bytes: 18432
//AOJ0033
/*
Sample Input
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
Output for the Sample Input
YES
NO*/
#include <bits/stdc++.h>
using namespace std;
int a[15],l[15],r[15];
bool wyh;
void dfs(int i,int j, int k){
	if(i>10){
		wyh=true;
		return;
	}
	//if(wyh)return ;
	if(a[i]>l[j-1]){
		l[j]=a[i];
		dfs(i+1,j+1,k);
	}
	if(a[i]>r[k-1]){
		r[k]=a[i];
		dfs(i+1,j,k+1);
	}
	//return false;
}
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		for(int i=1;i<=10;i++){
			cin>>a[i];
		}
		wyh=false;
		dfs(1,1,1);
		if(wyh)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  char x;
  bool isFour=false;
  rep(i,N){
    cin >> x;
    if(x=='Y')isFour=true;
  }
  cout << (isFour?"Four":"Three") << endl;
  return 0;
}


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

int main()
{
  ll S;
  cin >> S;
  ll x2=0,y2=0;
  ll x1,y1,x3,y3;
  if(S<=1000000000){
    y1=S;
    x1=0;
    y3=0;
    x3=1;
  }else if(S<1000000000000000000){
    y1=1000000000;
    x3=S/1000000000+1;
    y3=1;
    x1=1000000000-S%1000000000;
  }else{
    y1=1000000000;
    x3=1000000000;
    y3=0;
    x1=0;
  }

  cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
  // cout << abs((x2-x1)*(y3-y2)-(x3-x2)*(y2-y1)) << endl;
}

Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    A2IN(ll, L, ll, R, N);
    REP(i, N)
    {
        ++R[i];
    }
    ll L_max = *max_element(ALL(L));
    ll R_min = *min_element(ALL(R));
    ll ans = 0;
    priority_queue<ii> l;
    pq_asc<ll> r;
    REP(i, N)
    {
        l.push({L[i], R[i]});
        if (R[i] == R_min)
        {
            l.push({L[i], R[i]});
        }
        if (L[i] == L_max)
        {
            r.push(R[i]);
        }
        CH(max, ans, max(0LL, R_min - L_max) + R[i] - L[i]);
    }
    ans = CH(max, ans, max(0LL, R_min - l.top().first) + max(0LL, r.top() - L_max));
    REP(i, N)
    {
        r.push(l.top().second);
        l.pop();
        CH(max, ans, max(0LL, R_min - l.top().first) + max(0LL, r.top() - L_max));
    }
    OUT(ans);
}

Measured memory_bytes: 5232
n=int(input())
a=list(map(int,input().split()))
if n==1:
  print(1)
  exit(0)
ans=0
f=0
for i in range(1,n):
  if f==0:
    if a[i]>a[i-1]:
      f=1
      ans+=1
    elif a[i]<a[i-1]:
      f=-1
      ans+=1
    # elif a[i]==a[i-1]:
    # if i==n-1:
    #   ans+=1
  elif f==1:
    if a[i]>=a[i-1]:
      pass
    elif a[i]<a[i-1]:
      # ans+=1
      f-=1
    if i==n-1 and f==0:
      ans+=1
  elif f==-1:
    if a[i]>a[i-1]:
      # ans+=1
      f+=1
    elif a[i]<=a[i-1]:
      pass
    if i==n-1 and f==0:
      ans+=1
print(ans)


Measured memory_bytes: 14100
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
#define N 101010
LL n , a , b , h[ N ];
void init(){
  n = getint();
  a = getint();
  b = getint();
  for( int i = 0 ; i < n ; i ++ )
    h[ i ] = getint();
}
LL okay( LL tms ){
  LL nd = 0;
  for( int i = 0 ; i < n ; i ++ ){
    if( b > 1000000000000LL / tms )
      continue;
    LL res = h[ i ] - b * tms;
    if( res <= 0 ) continue;
    nd += ( res + a - b - 1 ) / ( a - b );
  }
  return nd <= tms;
}
void solve(){
  LL bl = 1 , br = 1000000000000000LL , ba = br;
  while( bl <= br ){
    LL bmid = (bl + br) >> 1;
    if( okay( bmid ) ) ba = bmid , br = bmid - 1;
    else bl = bmid + 1;
  }
  cout << ba << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading;

namespace Atcoder
{
	class Program
	{
		//string s = Console.ReadLine();
		//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		//int H = intArray[0];
		//int W = intArray[1];
		//int N = int.Parse(Console.ReadLine());
		//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
		//Boolean ok = false;

		//Console.WriteLine(ans);
		//Console.WriteLine("Yes");
		//Console.WriteLine("No");
		//Console.ReadKey();
		//Console.WriteLine(cnt);

		//string[] strArray = Console.ReadLine().Split(' ').ToArray();
		//string S = strArray[0];
		//string T = strArray[1];
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			if (N == 1)
            {
				Console.WriteLine(Console.ReadLine());
				return;
            }
			
			List<BigInteger> clock = new List<BigInteger>();

			for(int i = 0;i < N; i++)
            {
				clock.Add(BigInteger.Parse(Console.ReadLine()));
            }

			BigInteger num = clock[0];

			for (int i = 1; i < N; i++)
			{
				num = Lcm(num, clock[i]);
			}
			Console.WriteLine(num);
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}
		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 28388
#include <iostream>
using namespace std;
int main()
{
	long long k = 0;
	int x = 1;
	int n;
	int a[1000];
	cin >> n;
	for(int i = 0;i < n;i++)cin >> a[i];
	
	bool flag = true;
	while(flag)
		{
			for(int i = 0;i < n;i++)
				{
					if(a[i] % 2 != 0)
						{
							flag = false;
						}
				}
			if(flag)
			   {
			   	    for(int i = 0;i < n;i++)
			   	        {
			   	        	a[i] /= 2;
						}
			   }
			k++;
		}
	cout << k-1 << endl;
	return 0;
 } 

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

  vi a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];

  vvi c(100001);
  rep(i, 0, n) c[a[i]].pb(b[i]);

  priority_queue<int> que;
  int ans = 0;
  rep(i, 1, m+1) {
    for(auto j : c[i]) que.push(j);
    if(!que.empty()){
      ans += que.top();
      que.pop();
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7296
from collections import deque
N, X, Y = map(int, input().split())

graph = []
graph.append([1])
for i in range(1, N-1):
    graph.append([i-1, i+1])
graph.append([N-2])

graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0]*N

def bfs(num):
    dq = deque()
    dq.append((num,0))
    visited = [-1]*N
    visited[num] = 0
    while dq:
        a, b = dq.popleft()
        for i in graph[a]:
            if visited[i] == -1:
                visited[i] = b+1
                dq.append((i, b+1))
    return visited

vx = bfs(X-1)
vy = bfs(Y-1)

for i in range(0,N-1):
    for j in range(i+1, N):
        if abs(X-1-i) <= abs(Y-1-i):
            idx = min(j-i, abs(X-1-i) + vx[j])
        else:
            idx = min(j-i, abs(Y-1-i) + vy[j])
        cnt[idx] += 1
    
for i in cnt[1:]:print(i)



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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;

int main() {
    ll x; cin >> x;

    ll ans = 0;
    ans += 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);
    OP(ans);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
int main()
{
    int n, debt = 100000;
    cin >> n;
    for (int i = 0; i < n; i++) {
        debt *= 1.05;
        if (debt % 1000 != 0) {
            debt += 1000 - debt % 1000;
        }
    }
    cout << debt << endl;
    return 0;
}


Measured memory_bytes: 3076
n, a, b = map(int, input().split())
ans = 0
if (b - a) % 2 == 0:
    ans = (b - a) // 2
else:
    # ans += (b - a) // 2
    # a += ans
    # b -= ans
    # ans += min(n - a, b - 1)
    if a - 1 <= n - b:
        ans += a
        b -= a
        a = 1
    else:
        ans += n - b + 1
        a += n - b + 1
        b = n
    ans += (b - a) // 2
print(ans)

Measured memory_bytes: 38256
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;

const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, 1, 0, -1};
const char* dir_str = "NESW";
char field[110][110];
long long steps[4][110][110];

int main() {
  int H, W;
  long long L;
  while (scanf("%d%d%lld", &H, &W, &L), H|W|L) {
    memset(field, '#', sizeof(field));
    memset(steps, -1, sizeof(steps));

    int sy = -1, sx = -1, sdir = -1;
    for (int y = 1; y <= H; ++y) {
      for (int x = 1; x <= W; ++x) {
        scanf(" %c", &field[y][x]);
        if (isalpha(field[y][x])) {
          switch (field[y][x]) {
          case 'N': sdir = 0; break;
          case 'E': sdir = 1; break;
          case 'S': sdir = 2; break;
          case 'W': sdir = 3; break;
          }
          field[y][x] = '.';
          sy = y; sx = x;
        }
      }
    }

    int yy = sy, xx = sx, dir = sdir;
    for (long long k = 0; k < L; ++k) {
      if (steps[dir][yy][xx] == -1) {
        steps[dir][yy][xx] = k;
      } else {
        long long rest = L - k;
        long long period = k - steps[dir][yy][xx];
        k = L - rest % period;
        if (k == L) { break; }
      }

      int ny = yy + dy[dir], nx = xx + dx[dir];
      while (field[ny][nx] == '#') {
        dir = (dir + 1) % 4;
        ny = yy + dy[dir]; nx = xx + dx[dir];
      }
      yy = ny; xx = nx;
    }

    printf("%d %d %c\n", yy, xx, dir_str[dir]);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 0;
string s;

vl A;

void input() {
  IN(N);
  IN(K);
  REP(i, N) {
    IN(t);
    A.pb(t);
  }
  sort(ALL(A));
}

void solve() {
  ll ok = 1e18;
  ll ng = -1e18;
  while (abs(ok - ng) > 1) {
    // DEBUG(ok);
    // DEBUG(ng);
    // LN();
    ll mid = (ok + ng) / 2;
    ll cnt = 0;

    for (ll e : A) {
      if (e == 0) {
        cnt += (0 <= mid ? N - 1 : 0);
        continue;
      }
      if (e < 0 && e * A.back() <= mid) {
        ll ok2 = N - 1, ng2 = -1;
        while (abs(ok2 - ng2) > 1) {
          ll mid2 = (ok2 + ng2) / 2;
          (e * A[mid2] <= mid ? ok2 : ng2) = mid2;
        }
        cnt += N - ok2;
        cnt -= (e * e <= mid);
      } else if(0 < e && e * A[0] <= mid) {
        ll ok2 = 0, ng2 = N;
        while (abs(ok2 - ng2) > 1) {
          ll mid2 = (ok2 + ng2) / 2;
          (e * A[mid2] <= mid ? ok2 : ng2) = mid2;
        }
        cnt += ok2 + 1;
        cnt -= (e * e <= mid);
      }
    }
    (K <= cnt / 2 ? ok : ng) = mid;
  }
  PRINT(ok);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 2420
N=int(input())
A=[0]+list(map(int,input().split()))+[0]

x=[0]
x[0]=A[0]
for i in range(2,N+3):
    x.append(x[i-2]+abs(A[i-1]-A[i-2]))

for i in range(1,N+1):
    ans=0
    ans+=x[i-1]+abs(A[i-1]-A[i+1])+x[-1]-x[i+1]
    print(ans)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N;
    cin >> N;
    if(N<1200){
        cout << "ABC";
    }else if (N<2800)
    {
        cout << "ARC";
    }else{
        cout << "AGC";
    }
    

}


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

int main () {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    vector<int> b(n), c(i+1);
    for (int j = 0; j <= i; j++) {
      c.at(j) = a.at(j);
    }
    sort(c.begin(), c.end());
    for (int j = 0; j <= i; j++) {
      b.at(j) = c.at(j);
    }
    if (i != n-1) {
      for (int j = i+1; j < n; j++) {
        b.at(j) = a.at(j);
      }
    }
    for (int j = 0; j < n; j++) {
      if (j == n-1) cout << b.at(j) << endl;
      else cout << b.at(j) << ' ';
    }
  }
}


Measured memory_bytes: 3148
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int grid[][] = new int[3][3];
        for(int i = 0; i < 3; i++ ){
            for(int j = 0; j < 3; j++){
                grid[i][j] = sc.nextInt();
            }
        }
        
        String ans = "No";
        for(int i = 0; i <= grid[0][0]; i++ ){
            int a0 = i;
            int b0 = grid[0][0] - a0;
            int a1 = grid[1][0] - b0;
            int a2 = grid[2][0] - b0;
            
            boolean isOK = true;
            for(int y = 1; y <3; y++ ){
                int by1 = grid[0][y] - a0;
                int by2 = grid[1][y] - a1;
                int by3 = grid[2][y] - a2;
                
                if( by1 < 0 || by2 < 0 || by3 < 0 ) {
                    isOK = false;
                    break;
                }
                if( by1 != by2 || by2 != by3 ) {
                    isOK = false;
                    break;
                }
            }
            
            if( isOK ) {
                ans = "Yes";
                break;
            }
        }
        System.out.println( ans );
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S,T;

vector<int> A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S>>T;
	
	if(N<3) {
		int ret=0;
		FOR(i,N) ret+=S[i]!=T[i];
		cout<<ret<<endl;
		return;
	}
	
	if(S[0]=='1') A.push_back(0);
	if(T[0]=='1') B.push_back(0);
	for(i=1;i<N;i++) {
		if(S[i]!=S[i-1]) A.push_back(i);
		if(T[i]!=T[i-1]) B.push_back(i);
	}
	
	int mi=1<<30;
	for(int D=-(N+2);D<=N+2;D++) if(D%2==0) {
		int tot=0;
		FOR(i,A.size()) {
			y=i+D;
			if(y<0) r=0;
			else if(y>=B.size()) r=N;
			else r=B[y];
			tot+=abs(A[i]-r);
		}
		FOR(i,B.size()) {
			y=i-D;
			if(y>=0 && y<A.size()) continue;
			if(y<0) r=0;
			else r=N;
			tot+=abs(B[i]-r);
		}
		
		mi=min(mi,tot);
	}
	
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/abc137/tasks/abc137_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")
#define DUMPB(a, n) REP(i, n) printf("%c%c", a[i] ? 'o' : '-', i + 1 == n ? '\n' : ' ')
#define DUMPLL(a, n) REP(i, n) printf("%lld%c", a[i], i + 1 == n ? '\n' : ' ')

const int N_MAX = 2500;
const int M_MAX = 5000;
const int C_I_MAX = 1e5;
const int P_MAX = 1e5;

int N, M, P;
int A[M_MAX];
int B[M_MAX];
int C[M_MAX];

//------------------------------------------------------------------------------
const int V_MAX = N_MAX;
const int E_MAX = M_MAX;
const int INF = 1e9;

struct edge { int from, to, cost; };

int V, E;
edge es[E_MAX];
int d[V_MAX];
bool r[V_MAX];
bool np[V_MAX];

void bellman_ford(int s) {
  fill(d, d + V, INF);
  d[s] = 0;
  r[s] = true;
  REP(i, V) {
    REP(j, E) {
      edge e = es[j];
      if (r[e.from]) r[e.to] = true;
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        if (i + 1 >= V) np[e.to] = true;
      }
    }
  }
  REP(i, V - 1) {
    REP(j, E) {
      edge e = es[j];
      if (r[e.from] && np[e.from]) np[e.to] = true;
    }
  }
  // DUMP(d, V);
  // DUMPB(np, V);
}

//------------------------------------------------------------------------------
void solve() {
  V = N; E = M;
  REP(i, M) es[i] = { A[i] - 1, B[i] - 1,  P - C[i] };
  bellman_ford(0);
  if (np[N - 1]) puts("-1");
  else printf("%d\n", max(-d[N - 1], 0));
}

void input() {
  scanf("%d%d%d", &N, &M, &P);
  REP(i, M) scanf("%d%d%d", A + i, B + i, C + i);
}

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


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

int main() {
    long long n, ret = 0;
    std::cin >> n;
    std::unordered_map<long long, int> m;
    for (int i = 0; i < n; i++) {
        long long t;
        std::cin >> t;
        m[t]++;
    }
    for (auto& el : m) if (el.second % 2) ret++;
    std::cout << ret << std::endl;

    return 0;
}

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

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


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

    int    count = 0;
    string forecast;
    string weather;
    cin >> forecast;
    cin >> weather;
    int sz = (int) forecast.size();
    rep(i, sz) {
        if (forecast.at(i) == weather.at(i)) {
            count++;
        }
    }
    cout << count << endl;


    return 0;
}


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

int ans=0;
  if(S.size()==1){
cout<<0<<endl;
  }
  else{

for(int i=1;i<S.size();i++){
  if(S[i-1]==S[i]){
    ans++;
    if(S[i-1]=='1'){
      S[i]='0';
    }
    else{
      S[i]='1';
    }
  }
}
cout<<ans<<endl;
  }
}


Measured memory_bytes: 512