akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int int_cmp(const int *a, const int *b)
{
  if (*a < *b)
    return (-1);
  else if (*a > *b)
    return (1);
  return (0);
}
 
 
int main()
{
  int n,q,i,x,j;
  int array_n[100000];
  int array_q[50000];
  int count=0;
 
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&array_n[i]);
  }
  qsort(array_n,n,sizeof(array_n[0]),(int(*)(const void*, const void*))int_cmp);
 
  scanf("%d",&q);
  for (i=0;i<q;i++){
    scanf("%d",&x);
    int l=0;
    int r=n-1;
    int m;
    while (l<=r){
      m=(l+r)/2;
      if (array_n[m]==x){
        count++;
        break;
      }else if(array_n[m]<x){
        l=m+1;
      }else if(array_n[m]>x){
        r=m-1;
      }
    }
  }
 
  printf("%d\n",count);
 
  return 0;
}

Measured memory_bytes: 1040
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if (b-1)%(a-1) == 0 {
		fmt.Println((b - 1) / (a - 1))
	} else {
		fmt.Println((b-1)/(a-1) + 1)
	}
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int N, X;
  cin >> N >> X;

  vi m(N);
  int sum = 0;
  int small = INF;
  rep(i, 0, N) {
    cin >> m[i];
    sum += m[i];
    if (m[i] < small) {
      small = m[i];
    }
  }  
  int ans = N + (X - sum) / small;
  
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);                 // 標準入出力高速化
  std::ios_base::sync_with_stdio(false); // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15); // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = [x//400 for x in A]
a,b = 0,0
for i in range(13):
    if i < 8:
        if i in B:
            a+=1
    else:
        b+=B.count(i)
print(max(a,1),a+b)


Measured memory_bytes: 2940
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n = -1;

	vector<int> score;

	while (true)
	{
		int sum = 0;

		cin >> n;

		if (n == 0) { break; }

		vector<int> D(n);

		for (int i = 0; i < n; ++i)
		{
			cin >> D[i];

			sum += D[i];
		}

		sum -= *max_element(D.begin(), D.end());
		sum -= *min_element(D.begin(), D.end());

		score.push_back(static_cast<int>(sum / (D.size() - 2) + 0.5));
	}

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

	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define max(a,b) (((a)>(b))?a:b)
#define min(a,b) (((a)<(b))?a:b)
#define int long long
using namespace std;
template<typename T>void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-48;
	x*=f;
}
int x[1010],y[1010],ji[2],n,d[50];
signed main(){
//	freopen("t.in","r",stdin);
//	freopen("wa.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i)
		read(x[i]),read(y[i]),ji[(x[i]+y[i])&1]++;
	if(ji[0]&&ji[1]){puts("-1");return 0;}
	int uss=31;
	for(int i=1;i<=uss;++i)
		d[uss-i+1]=(1<<(i-1));
	if(ji[0]) uss++;d[uss]=1;
	cout<<uss<<endl;
	for(int i=1;i<=uss;++i)
		cout<<d[i]<<" ";
	cout<<endl;
	//0---29
	for(int i=1;i<=n;++i){
		int nx=0,ny=0;
		for(int j=1;j<=uss;++j){
			int dx,dy;
			if(x[i]>nx) dx=abs(nx+d[j]-x[i])+abs(y[i]-ny);
				else dx=abs(nx-d[j]-x[i])+abs(y[i]-ny);
			if(y[i]>ny) dy=abs(ny+d[j]-y[i])+abs(x[i]-nx);
				else dy=abs(ny-d[j]-y[i])+abs(x[i]-nx);
			if(dx<dy) {
				if(x[i]>nx) putchar('R'),nx+=d[j];
				else putchar('L'),nx-=d[j];
			}
			else{
				if(y[i]>ny) putchar('U'),ny+=d[j];
				else putchar('D'),ny-=d[j];
			}			 
		}
		cout<<endl;
		if(x[i]!=nx||y[i]!=ny) while(true) nx++;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;  
public class Main{
   public static void main(String[] args){
	   Scanner sc = new Scanner(System.in);
	   int N = sc.nextInt();
	   int i;
	   int pow=1;
	   double ans=1;
 for(i = 1; i <= N; i++){
     //pow = pow * i;
     ans = (ans*i) % (Math.pow(10.0,9.0)+7.0);
 }
 System.out.println((int)ans);
     }
 }

Measured memory_bytes: 25684
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = A.copy()
    for i in range(N):
        B[i] += (i + 1)

    cnt = {}
    for b in B:
        if b not in cnt:
            cnt[b] = 1
        else:
            cnt[b] += 1

    res = 0
    for i in range(N - 1, -1, -1):
        r = (i + 1) - A[i]
        if r in cnt:
            res += cnt[r]

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116180
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmn=[](auto&x,auto y){if(x>y){x=y;return true;}return false;};
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    std::vector<i64> a(4);
    for (i64& x: a) std::cin >> x;
    i64 n;
    std::cin >> n;

    for (usize i=0; i<3; i++) {
        cmn(a.at(i+1), 2*a.at(i));
    }

    std::cout << n%2*a.at(2) + n/2*a.at(3) << '\n';
}


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

const int MAXN = 2e6 + 5; 
const int MOD = 1e9 + 7; 

int pow_mod (int a, int b){
    if(b==0)return 1; 
    
    int x = pow_mod(a,b/2); 
    x=(x*x)%MOD; 
    if(b&1) x=(x*a)%MOD; 
    
    return x; 
}
inline int get_inv (int x){
    return pow_mod (x, MOD - 2);
}

int fact [MAXN]; 
int inv_fact [MAXN]; 
main(){
    ios_base::sync_with_stdio(0); 
    fact[0]=1;
    for (int i=1;i<MAXN;i++) fact[i]=(i*fact[i-1])%MOD; 
    for (int i=0;i<MAXN;i++) inv_fact[i]=get_inv(fact[i]); 
    
    int K; cin>>K; 
    string s; cin >> s; 
    
    int N = s.length(); 
    int ans = 0; 
    
    for (int end=0; end<=K; end++){
        int cnt = (pow_mod(26, end) * pow_mod (25, K - end)) % MOD;
        // (K - end + N - 1, N - 1)
        int num = fact[K - end + N - 1]; 
        int denom = (inv_fact[K - end] * inv_fact[N - 1]) % MOD;
        num = (num * denom) % MOD; 
        cnt = (cnt * num) % MOD; 
        ans = (ans + cnt) % MOD; 
    }
    cout << ans << '\n'; 
    return 0; 
}

Measured memory_bytes: 35460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>


using namespace std;

int main() {

  int k,a,b;
  cin>>k>>a>>b;
  bool s = false;
  for(int i = a;i<=b;i++){
    if(i%k==0) s = true;
  }
  if(s==true)
    cout<<"OK"<<endl;
  else
    cout<<"NG"<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    long long n;
    string s;
    cin >> n;
    if (n % 2 == 0) {
        cout << n << endl;
    } else {
        cout << 2 * n << endl;
    }
}

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

int N, M;

vector<vector<int>> adjList(100100);
bool visited[100100];
int dist[100100];

int vcnt;

void bfs() {
    vcnt = 1;
    queue<int> q;
    q.push(1);
    dist[1] = 0;

    visited[1] = true;
    while (!q.empty()) {
        int here = q.front();
        q.pop();
        for (int i = 0; i < adjList[here].size(); ++i) {
            int there = adjList[here][i];
            if (!visited[there]) {
                q.push(there);
                visited[there] = true;
                dist[there] = here;
                ++vcnt;
            }
        }
    }
}

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


    memset(visited, 0, sizeof(visited));
    memset(dist, 0, sizeof(dist));

    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        adjList[a].push_back(b);
        adjList[b].push_back(a);
    }

    bfs();

    if (vcnt == N) {
        printf("Yes\n");
        for (int i = 2; i <= N; ++i) {
            printf("%d\n", dist[i]);
        }
    }
    else {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 10376
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        String s = kbd.next();
        String[] tail = s.split("");

        if (blackFirst(tail) >= whiteFirst(tail)) {
            System.out.println(whiteFirst(tail));
        } else {
            System.out.println(blackFirst(tail));
        }
    }

    static int blackFirst(String[] arr) {
        if (arr.length == 0) {
            return 0;
        }
        int coun = 0;
        for (int i = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                if (arr[i].equals("0")) {
                    continue;
                } else {
                    coun++;
                }
            } else {
                if (arr[i].equals("1")) {
                    continue;
                } else {
                    coun++;
                }
            }
        }
        return coun;
    }

    static int whiteFirst(String[] arr) {
        if (arr.length == 0) {
            return 0;
        }
        int coun = 0;
        for (int i = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                if (arr[i].equals("1")) {
                    continue;
                } else {
                    coun++;
                }
            } else {
                if (arr[i].equals("0")) {
                    continue;
                } else {
                    coun++;
                }
            }
        }
        return coun;
    }
}

Measured memory_bytes: 34396
open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let () =
  let n = read_int () in
  let al = read_list int_of_string in
  let rec iter sn ar mx = function
      x :: [] -> mx
    | x :: xs -> let sn' = sn + x in
                 let ar' = ar - x in
                 iter sn' ar' (min (abs (sn' - ar')) mx) xs
    | _ -> failwith "splitting_pile"
  in
  let sn = List.hd al in
  let ar = List.fold_left (+) 0 (List.tl al) in
  iter sn ar (abs (sn - ar)) (List.tl al) |> string_of_int |> print_endline


Measured memory_bytes: 25600
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);

            for (int i = 1; i <= 10; i++)
            {
                if (i * 1000 >= N)
                {
                    Console.Write (i * 1000 - N);
                    return;
                }
            }
        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 27524
import math 
def primeFactors(n):
    pf = []
    while n % 2 == 0: 
        pf.append(2) 
        n = n / 2 
    for i in range(3,int(math.sqrt(n))+1,2): 
        while n % i== 0: 
            pf.append(i) 
            n = n / i 
    if n > 2: 
        pf.append(n) 
    return pf
n = int(input())
pf = primeFactors(n)

dic = {}
for i in pf:
    try:
        dic[i] += 1
    except:
        dic[i] = 1
ans = 0
for i in dic:
    c = dic[i]
    tmp = (((1 + 8 * c) ** (0.5)) - 1) // 2
    ans += tmp
print(int(ans))

Measured memory_bytes: 9488
#include <cstdio>

#define maxn 50

int f[maxn + 1]['z' - 'a' + 1];
int main() {
    int n;
    scanf("%d", &n);
    for (int j = 1; j <= 'z' - 'a' + 1; j++) {
           f[0][j] = maxn * maxn + 1;
    }
    char ch = fgetc(stdin);
    for (int i = 1; i <= n; i++) {
        ch = fgetc(stdin);
        while (ch != '\n') {
            f[i][ch - 'a' + 1]++;
            ch = fgetc(stdin);
        }
        for (int j = 1; j <= 'z' - 'a' + 1; j++) {
            if (f[i][j] < f[0][j])
                f[0][j] = f[i][j];
        }
    }
    for (int j = 1; j <= 'z' - 'a' + 1; j++) {
        while (f[0][j] > 0) {
            ch = 'a' + j - 1;
            printf("%c", ch);
            f[0][j]--;
        }
    }

    printf("\n");
    return 0;
}


Measured memory_bytes: 128
n,m,c=map(int,input().split())
b=[int(i) for i in input().split()]
mat=[]
for i in range(n):
    l=[int(i) for i in input().split()]
    mat.append(l)
cnt=0 
for i in range(n):
    sm=0
    for j in range(m):
        sm+=mat[i][j]*b[j]
    if sm+c>0:
        cnt+=1   
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
 
int main() {
  int n, m, k; cin >> n >> m >> k;
  vector<ll> a(n+1), b(m);
  rep(i, n){
   cin >> a[i+1];
   a[i+1] += a[i];
  }
  rep(i, m){
   cin >> b[i];
   if(i >= 1) b[i] += b[i-1]; 
  }
  
  int ans = 0;
  rep(i, n+1){
      if (a[i] > k) break;
        int b_r = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
        ans = max(ans, i + b_r);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mod  998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
bool isvalid(ll x,ll y,ll n, ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
vector<ll>v[100011];

int main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;

    cin>>n>>k;

    ll ap[n+11];

    for(ll i=0; i< n; i++){

        cin>>ap[i];
    }
    sort(ap, ap+n);

    ll sum = 0;
    for(ll i=0;i<k;i++){

        sum += ap[i];
    }

    cout<<sum;

    return 0;
}

Measured memory_bytes: 6016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            for (int i = 1; i < 100; i++)
            {
                var a = Pow(2, i);
                if (N < a)
                {
                    WriteLine(a/2);
                    return;
                }
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 18028
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
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 pf(s): return print(s, flush=True)


def main():
    m,n = LI()
    a = [[c for c in S()] for _ in range(m)]
    ad = collections.defaultdict(list)
    for i in range(m):
        for j in range(n):
            if a[i][j] != '.':
                ad[a[i][j]].append((i,j))
    ps = set(map(tuple,ad.values()))
    f = True
    r = 0
    while f:
        f = False
        for pa,pb in list(ps):
            i1,j1 = pa
            i2,j2 = pb
            if i1 == i2:
                ff = abs(j1-j2) > 1
                for j in range(min(j1,j2)+1,max(j1,j2)):
                    if a[i1][j] != '.':
                        ff = False
                        break
                if ff:
                    f = True
                    a[i1][j1] = '.'
                    a[i2][j2] = '.'
                    ps.remove((pa,pb))
                    r += 2
            elif j1 == j2:
                ff = abs(i1-i2) > 1
                for i in range(min(i1,i2)+1,max(i1,i2)):
                    if a[i][j1] != '.':
                        ff = False
                        break
                if ff:
                    f = True
                    a[i1][j1] = '.'
                    a[i2][j2] = '.'
                    ps.remove((pa,pb))
                    r += 2
            else:
                i,j = i1,j2
                ff = a[i][j] == '.'
                for j3 in range(min(j,j1)+1,max(j,j1)):
                    if a[i][j3] != '.':
                        ff = False
                        break
                for i3 in range(min(i,i2)+1,max(i,i2)):
                    if a[i3][j] != '.':
                        ff = False
                        break
                if ff:
                    f = True
                    a[i1][j1] = '.'
                    a[i2][j2] = '.'
                    ps.remove((pa,pb))
                    r += 2
                    continue

                i,j = i2,j1
                ff = a[i][j] == '.'
                for j3 in range(min(j,j2)+1,max(j,j2)):
                    if a[i][j3] != '.':
                        ff = False
                        break
                for i3 in range(min(i,i1)+1,max(i,i1)):
                    if a[i3][j] != '.':
                        ff = False
                        break
                if ff:
                    f = True
                    a[i1][j1] = '.'
                    a[i2][j2] = '.'
                    ps.remove((pa,pb))
                    r += 2

    return r



print(main())



Measured memory_bytes: 11204
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		long result = 0;
		//int cnt = 1;
		int now = 1;
		int to = n;
		boolean flg = false;
		if(n%2 != 0) flg = true;
		int[][] list = new int[m][2];
		for(int i = 0; i < m; i++){
		    list[i][0] = now;
		    list[i][1] = to;
		    now++;
		    to--;
		    if(!flg && n/4 == i+1){
		        flg = true;
		        now++;
		    }
		    //cnt++;
		}
		
		// 出力
		for(int i = 0; i < m; i++){
		    System.out.println(list[i][0] + " " + list[i][1]);
		}
		//System.out.println(result);
	}
}



Measured memory_bytes: 48004
n=int(input())
A=list(map(int,input().split()))
A.sort()
ans=int(0)
for i in range(n-2):
    for j in range(i+1,n-1):
        now=A[i]+A[j]
        l=int(j+1)
        r=int(n)
        while r-l>=1:
            x=int((r+l)/2)
            if A[x]<now:
                l=x+1
            else:
                r=x
        ans+=r-j-1
print(ans)

Measured memory_bytes: 43612
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
    int N,Q;
    cin >> N >> Q;
    vector<int> vec[N];
    for(int i = 0;i < Q;i++) {
        int A;
        cin >> A;
        if(A == 0) {
            int B,C;
            cin >> B >> C;
            vec[B].push_back(C);
        }
        else if(A == 1) {
            int B;
            cin >> B;
            for(int j = 0;j < vec[B].size();j++) {
                if(j != vec[B].size() - 1) {
                    cout << vec[B].at(j) << " ";
                }
                else {
                    cout << vec[B].at(j);
                }
            }
            cout << endl;
        }
        else {
            int B;
            cin >> B;
            vec[B].clear();
        }
    }
}


Measured memory_bytes: 8740
n,k=map(int,input().split())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])
l.sort()
sum=l[0][1]
i=0
while sum<k:
    i+=1
    sum+=l[i][1]
print(l[i][0])

Measured memory_bytes: 20104
#include <stdio.h>
       
int main(){
 int a,b;
 char c;
 while(1){
 scanf("%d %c %d",&a,&c,&b);
 if(c=='+'){
  printf("%d\n",(a+b));
 }else if(c=='-'){
  printf("%d\n",(a-b));
 }else if(c=='*'){
  printf("%d\n",(a*b));
 }else if(c=='/'){
  printf("%d\n",(a/b));
 }else if(c=='?'){
  break;
 }
 }
 return 0;
}

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


int main() {
 int A,B;
  cin >> A >>B;
  int a = A + B;
  int  b= A  -  B;
  int  c = A * B;
  int  x =max (a, max (b,c));
  cout << x <<endl;
}
  


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n+1; i++) {
        ll mi, ma;
        mi = (i-1)*i / 2;
        ma = (n-i+1 + n)*i /2;
        ans += (ma - mi) + 1;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
/*LCS gfg*/

void solve()
{
    ll n,w,i,j,m,x,y,z,k,h,mod = 1e9+7;
    cin >> h >> w;
    string a[h];
    for(i=0;i<h;i++)
        cin >> a[i];
    ll dp[h][w];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;

    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            if(i == 0 && j == 0)
                continue;
            if(a[i][j] == '#')
                dp[i][j] = 0;
            else
            {
                x = 0;
                y = 0;
                if(i-1 >= 0)
                    x = dp[i-1][j];
                if(j-1 >= 0)
                    y = dp[i][j-1];

                dp[i][j] = (x+y)%mod;
            }
        }
    }
    cout << dp[h-1][w-1]%mod;





}
int main()
{

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin >> t;
	while(t-- > 0)
	{
		solve();
	}

}


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

class Dice {
private:
    int* face;
    void SetNumber(int n0, int n1, int n2, int n3, int n4, int n5) {
        face[0] = n0;
        face[1] = n1;
        face[2] = n2;
        face[3] = n3;
        face[4] = n4;
        face[5] = n5;
    };

public:
    Dice(int number[]) {
        face = new int[6];
        for (int i = 0; i < 6; ++i) {
            face[i] = number[i];
        }
    };
    ~Dice() {
        delete[] face;
    };
    void Roll(char order) {
        switch (order) {
            case 'E':
                SetNumber(face[3], face[1], face[0], face[5], face[4], face[2]);
                break;
            case 'N':
                SetNumber(face[1], face[5], face[2], face[3], face[0], face[4]);
                break;
            case 'S':
                SetNumber(face[4], face[0], face[2], face[3], face[5], face[1]);
                break;
            case 'W':
                SetNumber(face[2], face[1], face[5], face[0], face[4], face[3]);
                break;
        }
    };
    bool isSame(int face2[]) {
        char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
        for (int i = 0; i < 24; ++i) {
            Roll(order[i]);
            for (int j = 0; j < 6; ++j) {
                if (face[j] != face2[j]) {
                    break;
                }
                if (j == 5) {
                    return true;
                }
            }
        }
        return false;
    };
};

int main() {
    int number[6];
    int res;
    for (int i = 0; i < 6; ++i) {
        cin >> res;
        number[i] = res;
    }
    Dice dice(number);
    for (int i = 0; i < 6; ++i) {
        cin >> res;
        number[i] = res;
    }
    if (dice.isSame(number)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var a = input[1].split(" ");
    a = a.map(str => parseInt(str, 10));
    var b = input[2].split(" ");
    b = b.map(str => parseInt(str, 10));
    var count = 0;
    for(var i = 0; i < n; i++){
        var atarget = a[i] + a[i+1];
        var rest = atarget - b[i];
        if(rest < 0){
            count += atarget;
            a[i+1] = 0;
        }else{
            count += b[i];
            a[i+1] = Math.min(rest,a[i+1]); 
        }
    }
	//出力
	console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int a,b,c; cin>>a>>b>>c;
  if (2*max(a, max(b, c))==a+b+c) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
k,x=map(int,input().split())
ans_min=max(-1000000,x-k+1)
ans_max=min(1000000,x+k-1)
ans=""
for i in range(ans_min,ans_max+1):
    if i==ans_min:
        ans+=str(i)
    else:
        ans+=" "+str(i)
print(ans)

Measured memory_bytes: 3060
p=input().split(" ")
a=int(p[0])
b=int(p[1])
c=a*10-1
d=int(a/0.07)-1
num=[]
ans=[]
for i in range(c,d+1):
    if int(i*0.08)==a:
        num.append(i)
l=len(num)

for i in range(l):
    if int(num[i]*0.1)==b:
        ans.append(num[i])
if ans==[]:
    print("-1")
else:
    print(ans[0])

Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    int n,m;
    cin>>n>>m;
    vector<int> p(m);
    vector<string> s(m);
    vector<bool> ac(n, false);
    vector<int> wa(n, 0);
    
    REP(i,m){
        cin>>p[i]>>s[i];
    }

    REP(i,m){
        if(!ac[ p[i]-1 ]){
            if(s[i] == "AC"){
                ac[ p[i] - 1 ] = true;
            } else {
                wa[ p[i] - 1 ]++;
            }
        }
    }

    int sumc = 0; int sump = 0;
    REP(i,n){
        if(ac[i]){
            sumc++;
            sump += wa[i];
        }
    }

    cout<<sumc<<" "<<sump<<endl;

    

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

Measured memory_bytes: 6528
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  std::string s;
  std::cin>>s;

  std::vector<std::string> day={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  
  rep(i,0,8){
    if(day[i]==s){
      std::cout<<7-i<<"\n";
      return 0;
    }
  }

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int k=0;
  for(int i=0;i<n;i++){
    if(p[i]!=i+1){
      k++;
    }
  }
  if(k<=2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

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

int main(){

    char s[3],t[3]; cin>>s>>t;

    int count = 0;

    for(int i=0; i<3; i++){
        if(s[i] == t[i])count++;
    }

    cout<<count<<endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    int n; cin >> n;
    vector<int> a(n), b(n, 0);
    REP(i, n) cin >> a[i];
    bool flag = false;
    int cnt = 0;
    int now = 0;
    REP(i, n){
        int nx = a[now];
        b[nx-1] = 1;
        now = nx - 1;
        cnt++;
        if(nx == 2){
            flag = true;
            break;
        }
    }
    if(flag) cout << cnt << endl;
    else cout << -1 << endl;
}

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

Measured memory_bytes: 1152
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	strVList := strings.Split(sc.Text(), " ")
	vList := []int{}
	for _, v := range strVList {
		intV, _ := strconv.Atoi(v)
		vList = append(vList, intV)
	}
	sc.Scan()
	strCList := strings.Split(sc.Text(), " ")
	cList := []int{}
	for _, v := range strCList {
		intV, _ := strconv.Atoi(v)
		cList = append(cList, intV)
	}
	res := 0
	for i := 0; i < n; i++ {
		diff := vList[i] - cList[i]
		if diff > 0 {
			res += diff
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 200005
#define ll long long
#define pi pair<int , int>
#define pip pair<pi ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
// this is triplet class , which will help us .
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
// this is for finding inversing multiplicative module of a number.
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
    lps[i] = j+1;
   i++;
   j++;
  }
  else{
    if(j != 0){
     j = lps[j-1];
    }
    else{
     lps[i] = 0;
     i++;
    }
  }
 }
 return lps[len-1];
}




vector<int> edges[N];
set<pi> st;
bool visited[N];
void dfs(vector<int>&comp , int S , int p){
       comp.pb(S);
       visited[S] = true;
      for(auto it:edges[S]){
           if(!visited[it]){
              dfs(comp , it , S);
           }
      }
}
int main(){
   ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    cout.tie(NULL);
     int n;
     cin>>n; 
     int m;
     cin>>m;
     for(int i = 0 ; i < m ; i++){
        int x , y;
        cin>>x>>y;
        st.insert({x , y});
        st.insert({y , x});
     }
     for(auto it:st){
          edges[it.f].pb(it.s);
         // edges[it.s].pb(it.f);
     }
     for(int i = 1;  i <= n ; i++)visited[i] = false;
      int maxi = 1;
     for(int i = 1 ; i<= n  ;i++)
       {
          if(!visited[i]){
          vector<int> comp;
          dfs(comp , i , -1);
          maxi = max(maxi , (int)comp.size());
          comp.clear();
       }
     }
     cout<<maxi<<endl;

     
}

Measured memory_bytes: 46500
url = "https://atcoder.jp//contests/abc066/tasks/abc066_b"

def main():
    pat = input()
    for i in range(len(pat) - 1, 0, -1):
        ind = i // 2
        a = ''.join(pat[:ind])
        b = ''.join(pat[ind:i:])
        if a == b:
            print(i)
            exit()
    print(1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}


int main() {
    vector<vector<int>> A(3,vector<int>(3));
    vector<vector<bool>> AA(3,vector<bool>(3,false));
    rep(i,3) {
        rep(j,3) {
             cin >> A[i][j];
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n) {
        cin >> b[i];
    }
    rep(i,n) {
        rep(j,3) {
            rep(k,3) {
                if (b[i]==A[j][k]) {
                    AA[j][k] = true;
                }
            }
            if (count(all(AA[j]), true)==3) {
                cout << "Yes" << "\n";
                return 0;
            }
        }
    }
    rep(j,3) {
        int cnt = 0;
        rep(i,3) {
            if (AA[i][j]==true) {
                cnt++;
            }
        } 
        if (cnt ==3) {
            cout << "Yes" << "\n";
            return 0;
        }
    }
    int cnt = 0;
    rep(i,3) {
        if (AA[i][i]== true) {
            cnt++;
        }
    }
    if (cnt==3) {
        cout << "Yes" << "\n";
        return 0;
    }
    if (AA[0][2]==true&&AA[1][1]==true&&AA[2][0]==true) {
        cout << "Yes" << "\n";
        return 0;
    }
    cout << "No" << "\n";
}


Measured memory_bytes: 256
from collections import deque

def main():
	h, w = list(map(int, input().split()))

	cs = [list(input()) for _ in range(h)]
	ds = [[10 ** 10 for _ in range(w)] for _ in range(h)]

	goal = (h - 1, w - 1)
	move = [(1, 0), (0, -1), (-1, 0), (0, 1)]
	q = deque()
	
	ds[0][0] = 0
	q.append((0, 0))

	while len(q) >= 1:
		cur = q.popleft()
		if cur == goal:
			break

		for i in range(4):
			if 0 <= cur[0] + move[i][0] < h and 0 <= cur[1] + move[i][1] < w:
				if cs[cur[0] + move[i][0]][cur[1] + move[i][1]] == ".":
					if ds[cur[0] + move[i][0]][cur[1] + move[i][1]] == 10 ** 10:
						q.append((cur[0] + move[i][0], cur[1] + move[i][1]))
						ds[cur[0] + move[i][0]][cur[1] + move[i][1]] = ds[cur[0]][cur[1]] + 1

	if ds[goal[0]][goal[1]] < 10 ** 10:
		print(counter(cs) - ds[goal[0]][goal[1]] - 1)
	else:
		print(-1)

def counter(cs):
	ans = 0
	for c in cs:
		ans += c.count(".")
	return ans

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
int v[9][2];
int h[9][2];
ll ch, cv;
template <typename T>
bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
map<ll, ll> mp;
void print(vector<int> v) {
    for(int i = 0; i < 9; i++) {
        cerr << v[i] << " ";
        if(i % 3 == 2) cerr << endl;
    }
}

ll f(vector<int> v) {
    ll ret = 0;
    for(int i = v.size() - 1; i >= 0; i--) {
        ret *= 10;
        ret += v[i];
    }
    return ret;
}

vector<int> g(ll a) {
    vector<int> ret;
    for(int i = 0; i < 9; i++) {
        ret.push_back(a % 10);
        a /= 10;
    }
    return ret;
}

typedef pair<ll, vector<int>> lll;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    for(int i = 0; i <= 8; i++) {
        h[i][0] = (i + 1) % 9;
        h[i][1] = (i + 8) % 9;
        v[i][0] = (i + 3) % 9;
        v[i][1] = (i + 6) % 9;
    }
    while(true) {
        cin >> ch >> cv;
        if(ch == 0) break;
        vector<int> start(9);
        vector<int> goal(9);
        for(int i = 0; i < 9; i++) cin >> start[i];
        for(int i = 0; i < 9; i++) cin >> goal[i];
        mp.clear();
        priority_queue<l_l, vector<l_l>, greater<l_l>> que;
        que.push({0, f(start)});
        while(true) {
            ll nowcost = que.top().first;
            ll nowval = que.top().second;
            vector<int> now = g(que.top().second);
            que.pop();
            if(now == goal) {
                cout << nowcost << endl;
                break;
            }
            int zeroindex;
            for(int i = 0; i < 9; i++) {
                if(now[i] == 0) zeroindex = i;
            }
            for(int i = 0; i < 2; i++) {
                ll newcost = nowcost + ch;
                vector<int> to = now;
                swap(to[zeroindex], to[h[zeroindex][i]]);
                auto a = f(to);
                if(mp.count(a) == 0 || mp[a] > newcost) {
                    mp[a] = newcost;
                    que.push({newcost, a});
                }
                /*
                cerr << "---------------" << endl;
                print(now);
                cerr << "to(horizon)" << endl;
                print(to);
                 */
            }
            for(int i = 0; i < 2; i++) {
                ll newcost = nowcost + cv;
                vector<int> to = now;
                swap(to[zeroindex], to[v[zeroindex][i]]);
                auto a = f(to);
                if(mp.count(a) == 0 || chmin(mp[a], newcost)) {
                    mp[a] = newcost;
                    que.push({newcost, a});
                }
                /*
                cerr << "---------------" << endl;
                print(now);
                cerr << "to(vertical)" << endl;
                print(to);
                 */
            }
        }
    }
    return 0;
}


Measured memory_bytes: 27452
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double m = sc.nextDouble();
    double a[] = new double[n];
    double sum = 0;
    
    for(int i=0;i<n;i++){
      a[i] = sc.nextDouble();
      sum += a[i];
    }
    int cnt = 0;
    double con = sum / 4 / m;
    
    for(int i=0;i<n;i++){
      if(a[i] >= con)
        cnt += 1;
    }
    
    String ans;
    if(cnt >= m)
      ans = "Yes";
    else
      ans = "No";

    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
n=int(input())
a=list(map(int,input().split()))
a2=sorted(set(a))
L=len(a2)
if n==1:print(a[0]);exit()
elif n==2:print(a[1]);exit()
ng=L
ok=0
while ng-ok>1:
    check=a2[(ok+ng)//2]
    cnt=0 #check以上の要素の数
    idx=n
    cl=[0]*(2*n+1)
    cl[n]=1
    Ru=0
    for i in range(n):
        if a[i]<check:
            Ru-=cl[idx]-1
            idx-=1
        else:
            idx+=1
            Ru+=cl[idx]+1
        cnt += Ru
        cl[idx]+=1
    if cnt >= ((n+1)*n//2)//2:
        ok = (ok+ng)//2
    else:
        ng = (ok+ng)//2
print(a2[ok])

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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();

		int[][] box = new int[n][3];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				box[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < n; i++) {
			Arrays.sort(box[i]);
			int a = box[i][0];
			int b = box[i][1];
			int c = box[i][2];
			if (c * c == a * a + b * b) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}

		}

	}

}

Measured memory_bytes: 34320
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>

using namespace std;


int main(int argc, const char * argv[]) {
    

    int n, k;
    
    long long ans = 0;
    
    cin >> n >> k;
    
    int h[n];
    
    for(int i=0; i<n; i++)
    {
        cin >> h[i];
    }
    
    //降順ソート
    sort(h, h+n, greater<>());
    
    for(int i=k; i<n; i++)
    {
        ans += h[i];
    }
    
    cout << ans << endl;
    
    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    ans += min(abs(t - 0), abs(t - k)) * 2;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3640
import math
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    tot = sum(A)

    cand = helper(tot)
    for i in cand:
        rems = []
        for j in range(N):
            r = A[j] % i
            if r > 0:
                rems.append(r)
        rems.sort()

        tot = sum(rems)
        prefixneg = [0]
        for j in range(len(rems)):
            prefixneg.append(prefixneg[-1] + rems[j])

        for j in range(len(rems)+1):
            pos = (len(rems)-j)*i - (tot - prefixneg[j])
            neg = prefixneg[j]
            if max(pos, neg) <= K:
                return i

    return 1


def helper(n):
    div = set()
    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            div.add(i)
            div.add(n//i)
    return sorted(list(div), reverse = True)

if __name__ == '__main__':
    print(main())

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

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

   if (N % 2) {
      cout << "No" << endl;
   } else {
      int flag = 1;
      for (int i = 0; i < N / 2; i++) {
         if (S.at(i) != S.at(N/2+i)) {
            flag = 0;
            break;
         }
      }
      if (flag == 1) {
         cout << "Yes" << endl;
      } else {
         cout << "No" << endl;
      }
   }
}

Measured memory_bytes: 256