akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        int l = 1, r = 1000000007;
        while (l < r) {
            int mid = l + (r - l) / 2;
            boolean check = check(nums, k, mid);
            if (check) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        System.out.println(l);
    }

    private static boolean check(int[] nums, int k, int mid) {
        int req = 0;
        for (int num : nums) {
            if (num > mid) {
                req += Math.ceil((double) num / mid) - 1;
            }
        }
        return req <= k;
    }
}

Measured memory_bytes: 60300
import scala.collection.mutable
import scala.io.StdIn
import java.util._

object Main extends App {
  val l = StdIn.readLine().split(" ").map(_.toInt)
  val n = l(0)
  val m = l(1)

  var q = new mutable.PriorityQueue[Long]()
  StdIn.readLine().split(" ").foreach(i => q += i.toLong)
  for (i <- 0 until m){
    q += (q.dequeue()/2)
  }
  println(q.toArray.reduceRight(_.asInstanceOf[Long] + _.asInstanceOf[Long]))
}


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

 

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

#define rep(i, from, to) for (int i = from; i < (to); ++i)

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

#define sz(x) (int) (x).size()

#define FOR(i, to) for (int i = 0; i < (to); ++i)

 

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pii;

typedef pair<double,double> pdd;

typedef vector<ll> vll;

typedef vector<pair<int,int>> vpi;

typedef pair<ll,ll> pll;

typedef vector<string> vs;

#define MOD 1000000007

#define Nmax 402020

#define INF 101010LL * 101010LL

ll N,M,V,P;
vll v;
ll sm[Nmax];


int cb(ll val) {
  int st = 0;
  int dr = N-1;
  int ret = 0;
  while(st <= dr) {
    ll mij = (st+dr)/2;
    if(v[mij] <= val) {
      dr = mij - 1;
      ret = mij;
    } else {
      st = mij + 1;
    }
  }
  return ret;
}



int main() {

  cin.sync_with_stdio(false);

  cin >> N >> M >> V >> P;
  FOR(i, N) {
    ll x;
    cin >> x;
    v.pb(x);
  }
  sort(all(v)); reverse(all(v));
  
  sm[0] = v[0];
  for(int i=1;i<N;++i) {
    sm[i] = v[i] + sm[i-1];
  }
  ll ret = 0;
  for(int i=0;i<N;++i) {
    if(v[i] >= v[P-1]) {
      ++ret;
      continue;
    }
    if(v[i] + M < v[P-1]) continue;
    ll p = cb(v[i] + M);
    p = max(p, P-1);
    //cout << v[i] << " " << p << endl;
    //cout << V - (P-1) - (N-i) << endl;
    ll cx = V - (P-1) - (N-i);
    if(cx <= 0) {
      ++ret;
      continue;
    }
    ll smx = p ? sm[i-1] - sm[p-1] : sm[i-1];
    
    ll sf = (v[i] + M) * (i - p) - smx;
    //cout << cx << endl;
    //cout << v[i] << " " << sf << endl;
    //cout << p << endl;
    if(sf >= cx * M) {
      ++ret;
      continue;
    }
  }
  cout << ret << endl;

  

}

 

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, C, D, res;
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  res =max_L(A*B, C*D);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int A, B, C, D, res;
//   rd(A, B, C, D);
//   res = max(A*B, C*D);
//   wt(res);
// }


Measured memory_bytes: 256
import fractions
a,b,K = map(int,input().split())
g = fractions.gcd(a,b)
cnt = 0
ans = 0
for i in range(g,0,-1):
    if g % i == 0:
        cnt += 1
        if cnt == K:
            ans = i
            break
    else:
        pass
print(ans)

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

using namespace std;

int t;

int ap[100009];

int n;
int v[100][100];

void verif()
{
    for(int i = 1; i <= t; i ++)
    {
        if(ap[i] == 0)
            return;
    }

    int i, j;
    for(i = 1; i <= t; i ++)
    {
        for(j = i + 1; j <= t; j ++)
        {
            int com = 0;
            for(int h = 1; h <= ap[i]; h ++)
            {
                for(int l = 1; l <= ap[j]; l ++)
                {
                    if(v[i][h] == v[j][l])
                        com ++;
                }
            }

            if(com != 1)
                return;
        }
    }

    cout << t << "\n";
    for(i = 1; i <= t; i ++)
    {
        if(ap[i] != 0)
        {
            cout << ap[i] << "\n";
            for(int h = 1; h <= ap[i]; h ++)
                cout << v[i][h] << " " ;
            cout << "\n";
        }
    }

    exit(0);

    cout << "\n";
}

void bkt(int k)
{
    if(k == n + 1)
    {
        verif();

        return;
    }

    int i, j;
    for(i = 1; i <= t; i ++)
    {
        v[i][++ ap[i]] = k;
        for(j = i + 1; j <= t; j ++)
        {
            v[j][++ ap[j]] = k;
            bkt(k + 1);
            -- ap[j];
        }
        -- ap[i];
    }
}


int last[1000009];

vector <int> rez[100009];

void sol(int m)
{
    cout << m + 1 << "\n";

    int i, j;
    for(i = 1; i <= m; i ++)
    {
        ap[i] ++;
        rez[1].push_back(i);
        last[1] = 0;
    }

    int urm = m + 1;
    for(j = 2; j <= m + 1; j ++)
    {
        for(int x = 1; x < j; x ++)
        {
            rez[j].push_back(rez[x][last[x]]);
            ap[rez[x][last[x]]] ++;

            if(ap[rez[x][last[x]]] == 2)
                last[x] ++;
        }

        last[j] = j - 1;
        for(int x = j; x <= m; x ++)
        {
            rez[j].push_back(urm);
            ap[urm] ++;
            urm ++;
        }

    }

    for(i = 1; i <= m + 1; i ++)
    {
        cout << m << " ";
        for(auto u : rez[i])
            cout << u << " ";
        cout << "\n";
    }
}

int main()
{
    cin >> n;

    if(n == 1)
    {
        cout << "Yes\n";
        cout << "2\n1 1\n1 1\n";

        return 0;
    }

    int i;
    for(i = 2; i * (i + 1) <= 2 * n; i ++)
    {
        if(i * (i + 1) == 2 * n)
        {
            cout << "Yes\n";

            sol(i);

            return 0;
        }
    }

    cout << "No\n";
    return 0;

    t = (n << 1);

    for(t = 1; t <= (n << 1); t ++)
    {
        bkt(1);

        cout << t << "GATA\n";
    }

    return 0;
}


Measured memory_bytes: 6784
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long H = sc.nextLong();
    	long index = 1;
    	long count = 0;
    	while (1 <= H) {
    		count += index;
    		H /= 2;
    		index *= 2;
    	}
    	System.out.println(count);
    }
}

Measured memory_bytes: 23764
import copy

w, h, n = [int(n) for n in input().split()]

a1 = [0]
a2 = [w]
a3 = [0]
a4 = [h]

for i in range(n):
    x, y, a = [int(n) for n in input().split()]
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    elif a == 4:
        a4.append(y)

x1, x2, y3, y4 = max(a1), min(a2), max(a3), min(a4)

if x1 < x2 and y3 < y4:
    s = (x2 - x1) * (y4 - y3)
else:
    s = 0

print(s)

Measured memory_bytes: 3444
#include<stdio.h>

void koria(int,int);

void koria(int i, int c){
 printf("%d %d\n", i, c);
}


static const int MAX = 500;
static const int INY = (1<<21);
 
int main(){
  int n;
  int i;
  int j;
  int u;
  int v;
  int c;
  int k;
  int min = INY;
  int M[MAX][MAX];
  int cost[MAX];
  int vis[MAX];
  int p[MAX];
   
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INY;
    }
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
 
 
 
  for(i=0;i<n;i++){
    cost[i]=INY;
    p[i]=-1;
    vis[i]=0;
  }
  cost[0]=0;
   
  while(1){
    u=-1;
    min=INY;
  
    for(i=0;i<n;i++){
      if (cost[i]<min && !vis[i]){
    u=i;
    min=cost[i];
      }
    }
     
    if(u==-1) break;
    vis[u]=1;
    int c = 0;
    for(v=0;v<n;v++){
      if(cost[u]+M[u][v]<cost[v] && !vis[v])

{
    cost[v]=cost[u]+M[u][v];
    p[v]=u;
      }
    }
  }

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

{
       c = cost[i];
       

     koria(i,c);
  }
 
  return 0;
}

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

signed main()
{
  int X,A,B; cin>>X>>A>>B;
  int N; cin>>N;
  for(int i=0;i<N;i++){
    string s; cin>>s;
    if(s=="nobiro"){
      X=max(0LL,X+A);
    }else if(s=="tidime"){
      X=max(0LL,X+B);
    }else{
      X=0;
    }
  }
  cout<<X<<endl;
  return 0;
}



Measured memory_bytes: 3208
def c_sentou():
    N, T = [int(i) for i in input().split()]
    Times = [int(i) for i in input().split()] + [float('inf')]  # 番兵追加
    return sum([min(T, Times[i + 1] - Times[i]) for i in range(N)])

print(c_sentou())

Measured memory_bytes: 25200
import Control.Monad
import Control.Applicative
import Data.List

main = do
  x <- readLn :: IO Int
  when ( x /= 0 ) $ do
    print $ solve x
    main

solve :: Int -> Int
solve x = (sum . map (f 0)) ls
  where ls = [5,10..x]
        f :: Int -> Int -> Int
        f ac y | y `mod` 5 == 0 = f (ac+1) (y `div` 5)
               | otherwise = ac
            

Measured memory_bytes: 4308
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(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 long double ld;
typedef pair<int,int> P;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
const int MOD = 1e9+7;
//struct area

//function area

//main area
int main(){
    ll n;
    cin >> n;
    ll sum = 0;
    ll sum_2 = 0;
    rep(i,n){
        ll k;
        cin >> k;
        sum += k;
        sum_2 += ((k*k)%MOD);
        sum %= MOD;
        sum_2 %= MOD;
    }
    ll k = (sum*sum % MOD);
    cout << ((k - sum_2 + MOD)%MOD * 500000004)%MOD << endl;
}
/*



*/

Measured memory_bytes: 3628
import sys

sd = input()
t = input()
NG = 'UNRESTORABLE'


def valid(os: int):
    if len(sd) <= os or len(sd) - os < len(t):
        return False
    for sc, tc in zip(sd[os:os+len(t)], t):
        if sc != tc and sc != '?':
            return False
    ans = ''
    for i, sc in enumerate(sd):
        if i < os:
            c = sc
        elif i < os + len(t):
            c = t[i - os]
        else:
            c = sc
        if c == '?':
            c = 'a'
        ans += c
    return ans


if len(t) > len(sd):
    print(NG)
    sys.exit()

for i in range(len(sd) - len(t) + 1):
    ans = valid(len(sd) - len(t) - i)
    if ans:
        print(ans)
        sys.exit()

print(NG)


Measured memory_bytes: 3064
from functools import lru_cache
import sys

sys.setrecursionlimit(10**6)


@lru_cache(maxsize=None)
def dp(n):
    if n == 1:
        return D
    cand = []
    if n % 2 == 0:
        cand.append(dp(n // 2) + A)
    if n % 2 == 1:
        cand.append(dp((n-1) // 2) + A + D)
        cand.append(dp((n+1) // 2) + A + D)
    if n % 3 == 0:
        cand.append(dp(n // 3) + B)
    if n % 3 == 1:
        cand.append(dp((n-1) // 3) + B + D)
        cand.append(dp((n+2) // 3) + B + 2 * D)
    if n % 3 == 2:
        cand.append(dp((n+1) // 3) + B + D)
        if n - 2 != 0:
            cand.append(dp((n-2) // 3) + B + 2 * D)
    if n % 5 == 0:
        cand.append(dp(n // 5) + C)
    if n % 5 == 1:
        cand.append(dp((n-1) // 5) + C + D)
        cand.append(dp((n+4) // 5) + C + 4 * D)
    if n % 5 == 2:
        if n - 2 != 0:
            cand.append(dp((n-2) // 5) + C + 2 * D)
        cand.append(dp((n+3) // 5) + C + 3 * D)
    if n % 5 == 3:
        if n - 3 != 0:
            cand.append(dp((n-3) // 5) + C + 3 * D)
        cand.append(dp((n+2) // 5) + C + 2 * D)
    if n % 5 == 4:
        cand.append(dp((n+1) // 5) + C + D)
        if n - 4 != 0:
            cand.append(dp((n-4) // 5) + C + 4 * D)
    cand.append(D * n)
    return min(cand)


T = int(input())
for i in range(T):
    N, A, B, C, D = [int(_) for _ in input().split()]
    dp.cache_clear()
    print(dp(N))



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int H, W;
vector<string> G;
vector<vector<int>> dist;
int bfs(int sx, int sy)
{
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
            dist[i][j] = -1;
    }
    dist[sx][sy] = 0;
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    while (!que.empty())
    {
        auto cur = que.front();
        que.pop();
        int x = cur.F, y = cur.S;
        for (int i = 0; i < 4; ++i)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < H && ny >= 0 && ny < W && G[nx][ny] == '.' && dist[nx][ny] == -1)
            {
                dist[nx][ny] = dist[x][y] + 1;
                que.emplace(nx, ny);
            }
        }
    }

    int ret = 0;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
            ret = max(ret, dist[i][j]);
    }
    return ret;
}

signed main()
{

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

    cin >> H >> W;
    G.resize(H);
    dist.assign(H, vector<int>(W));

    rep(i, 0, H) cin >> G[i];

    int res = 0;
    rep(i, 0, H)
    {
        rep(j, 0, W)
        {
            if (G[i][j] == '#')
                continue;
            res = max(res, bfs(i, j));
        }
    }
    cout << res << endl;
}

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

int main() {
  int n;
  cin >> n;
  set<int64_t> v;
  bool flag = 1;
  for (int i = 0; i < n; ++i) {
    int64_t x;
    cin >> x;
    if (v.count(x)) {
      flag = 0;
      break;
    }
    else v.insert(x);
  }
  if (flag) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 9600
#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);
  
  int odd_count=0;
  
  for(int i=0;i<N;i++){
    if(a.at(i)%2==1)
      odd_count++;
  }
  
  if(odd_count%2==0)
    cout<<"YES";
  else
    cout<<"NO";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
const int nax = 1e6 + 50, mod = 1e9+7;
ll fac[nax*2], fin[nax*2];

ll power(ll a, ll b){
	ll result = 1;
	while(b>0){
		if(b&1) result = (result*a)%mod;
		(a*=a)%=mod;
		b/=2;
	}
	return result;
}

ll inv(ll x){
	ll e = mod -2, r = 1;
	while(e){
		if(e&1) r=r*x%mod;
		x = x*x %mod;
		e>>=1;
	}
	return r;
}

ll ncr(ll a, ll b){
	if(b<0 || b > a) return 0;
	return fac[a] * fin[b] % mod * fin[a-b] % mod;
}


void solve(){
	int k; string s; cin >> k >> s;
	int n = s.size();
	fac[0] = 1;
	forn(i,1,nax*2) fac[i] = fac[i-1] * i % mod;
	fin[nax*2-1] = inv(fac[nax*2-1]);
	for(int i = nax*2-2; i>=0; --i) fin[i] = fin[i+1]*(i+1)%mod;
	ll ans = 0;
	forn(i,0,k+1){
		(ans += ncr(n+i-1,i) * power(26,k-i) % mod * power(25,i) %mod) %= mod;
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 35656
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  vector<pair<ll, int> > xy1(N);
  vector<pair<ll, int> > xy2(N);
  REP(i, N){
    cin >> X[i] >> Y[i];
    xy1[i] = {X[i]+Y[i], i};
    xy2[i] = {X[i]-Y[i], i};
  }
  sort(xy1.begin(), xy1.end());
  sort(xy2.begin(), xy2.end()); 
  int midx = xy1[0].second;
  int Midx = xy1[N-1].second;
  ll ans = abs(X[Midx]-X[midx]) + abs(Y[Midx]-Y[midx]);
  midx = xy2[0].second;
  Midx = xy2[N-1].second;
  ans = max(ans, abs(X[Midx]-X[midx]) + abs(Y[Midx]-Y[midx]));
  midx = xy2[N-1].second;
  Midx = xy2[0].second;
  ans = max(ans, abs(X[Midx]-X[midx]) + abs(Y[Midx]-Y[midx]));
  cout << ans << endl;
}

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

#define ll long long
#define ld long double
#define PI 3.14159265

ll arra[201000];
ll arrf[201000];
int n;
ll k;

bool check(ll m) {
	ll sum = 0;
	for(int i = 0; i < n; i++) {
		ll newCoef = m/arrf[i];
		if(newCoef < arra[i]) {
			sum += arra[i]-newCoef;
		}
	}
//	printf("sum: %lld\n", sum);
	if(sum > k) {
		return false;
	} else {
		return true;
	}
}

ll ans;
void bs(ll l, ll r) {
	if(r >= l) {
		ll m = (r-l)/2+l;
//		printf("%lld %lld %lld\n", l, m, r);
		if(check(m)) {
			ans = m;
			bs(l, m-1);
		} else {
			bs(m+1, r);
		}
	}
	return;
}

bool comp(ll a, ll b) {
	return (a > b);
}

int main() {
	scanf("%d %lld", &n, &k);
	
	for(int i = 0; i < n; i++) {
		scanf("%lld", &arra[i]);
	}
	for(int i = 0; i < n; i++) {
		scanf("%lld", &arrf[i]);
	}
	
	sort(arrf, arrf+n, comp);
	sort(arra, arra+n);
	
	bs(0, (ll)1 << 50);
	printf("%lld\n",ans);
	
}

Measured memory_bytes: 3456
r, c = [int(line) for line in input().split()]
nums = [list(map(int, input().split())) for _ in range(r)]

for i in range(r):
    calc_r = 0
    for j in range(c):
        calc_r += nums[i][j]
    nums[i].append(calc_r)

calc_c_lst = []
for i in range(c):
    calc_c = 0
    for j in range(r):
        calc_c += nums[j][i]
    calc_c_lst.append(calc_c)
sum_c = sum(calc_c_lst)
calc_c_lst.append(sum_c)
ans_lst = nums + [calc_c_lst]

for i in range(r + 1):
    print(ans_lst[i][0], end="")
    for j in range(1, c + 1):
        print("", ans_lst[i][j], end="")
    print()


Measured memory_bytes: 6756
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int X, N;
    cin >> X >> N;
    int ans, diff = 1e9;

    set<int> st;
    rep(i, N) {
        int p;
        cin >> p;
        st.insert(p);
    }

    for (int i = -100; i <= 200; i++) {
        if (st.count(i) == 0) {
            if (diff > abs(X - i)) {
                diff = abs(X - i);
                ans = i;
            }
        }
    }

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

Measured memory_bytes: 3632
#include <stdio.h>

#define Mod 1000000007

int main()
{
	int i, N, x[100001];
	scanf("%d", &N);
	for (i = 1, x[0] = -1; i <= N; i++) {
		scanf("%d", &(x[i]));
		if (x[i] > x[i-1] + 2) x[i] = x[i-1] + 2;
	}
	
	int k;
	long long ans = 1;
	for (i = 1; i < N && x[i] == x[i-1] + 2; i++);
	for (k = 0; k < N; k++) {
		ans = ans * (i - k) % Mod;
		if (i < N) {
			for (x[i] = x[i-1], i++; i < N && x[i] >= x[i-1] + 2; i++) x[i] = x[i-1] + 2;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}


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

int main(){
    int N,K; cin >> N >> K;
    int ans=1;
    rep(i,N){
        if(ans*2>=ans+K) ans+=K;
        else ans*=2;
    }
    cout << ans;
}

Measured memory_bytes: 256
import itertools
from collections import Counter

N = int(input())
V = [int(x) for x in input().split()]
EV_counter = Counter(V[::2])
OD_counter = Counter(V[1::2])

# 1種類しかないとき対策
EV_counter[-1] = 0
OD_counter[-2] = 0

# 上位2種しか使う必要がない
EV = EV_counter.most_common(2)
OD = OD_counter.most_common(2)

answer = N
for (k1,v1), (k2,v2) in itertools.product(EV,OD):
  if k1 == k2:
    continue
  x = (N - v1 - v2)
  if answer > x:
    answer = x

print(answer)


Measured memory_bytes: 18528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int a, b;
    cin >> a >> b;
    rep1(i, 20000) {
        if(floor(i * 0.08) == a && floor(i * 0.1) == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=sqrt(n);i>=1;i--){
		if(n%i==0){
			ans=n/i;
			break;
		}
	}
	ll ans2=0;
	while(ans!=0){
		ans2++;
		ans/=10;
	}
	cout <<ans2;
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		HashMap<Long,Long> h = new HashMap<>();
		long sum = 0;
		while(n--!=0) {
			long c = s.nextInt();
			if(h.containsKey(c)) {
				h.put(c, h.get(c)+1);
			}
			else {
				h.put(c, 1l);
			}
			sum+=c;
		}
		int q = s.nextInt();
		while(q--!=0) {
			long b = s.nextInt();
			long c = s.nextInt();
			if(!h.containsKey(b)) {
				System.out.println(sum);
				continue;
			}
			long times = h.get(b);
			sum-=times*b;
			sum+=times*c;
			h.remove(b);
			if(h.containsKey(c)) {
				h.put(c,h.get(c)+times);
			}
			else {
				h.put(c, times);
			}
			
			System.out.println(sum);
		}
			
		
	}

}


Measured memory_bytes: 67400
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for B - Problem Set
	var N int
	fmt.Scan(&N)

	sc.Split(bufio.ScanWords)
	var temp int
	D := make(map[int]int, N)
	for i := 0; i < N; i++ {
		temp = nextInt()
		D[temp]++
	}

	var M int
	M = nextInt()

	var T int
	for i := 0; i < M; i++ {
		T = nextInt()
		D[T]--
	}

	for _, v := range D {
		if v < 0 {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}


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

int main() {
  int64_t N;
  cin >> N;
  string ans;
  while(N > 0) {
    char c;
    if(N % 26 == 0) {
      c = 'z';
      N -= 26;
    }
    else {
      c = 'a' + N % 26 - 1;
      N -= N % 26;
    }
    ans = c + ans;
    N /= 26;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>


int main() {
  int a, b, c, d, e, k;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
  if((e - a) <= k) {
    printf("Yay!\n");
  } else {
    printf(":(\n");
  }
  return 0;
}

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

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(v,a,b) for(int v=(a); v<=(b); v++)
#define fr(v,a,b) for(int v=(a); v>=(b); v--)
#define rng(v,a,b) for(int v=(a); v<(b); v++)

using namespace std;
typedef long long ll;
template<typename T> T& chmax(T& a, T b) { a = a > b ? a : b; return a;}
template<typename T> T& chmin(T& a, T b) { a = a < b ? a : b; return a;}
//const int maxn;
int main()
{
	int n,d; cin >> n >> d;
	if(n%(2*d+1)) cout << n/(2*d+1)+1 << '\n';
	else cout << n/(2*d+1) << '\n';
	return 0;
}


Measured memory_bytes: 256
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // codeforces
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") // yandex

#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

void solve() {
	int a, b, c, k;
    sc(a, b, c, k);
    while(b <= a) b *= 2, k--;
    while(c <= b) c *= 2, k--;
    cout << ((k >= 0) ? "Yes" : "No");
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

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

long long int gcm(long long a,long long b){
	long long r,tmp;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}

int main(){
	int N;
	long long M;
	cin >> N >> M;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	for(auto &i:a)i/=2;
	
	int c=0;
	while(a[0]%2==0){
		a[0]/=2;
		c++;
	}
	
	for(int i=1;i<N;i++){
		int d=0;
		while(a[i]%2==0){
		a[i]/=2;
		d++;
		}
		if(c!=d){
			cout << "0" << endl;
			return 0;
		}
	}
	
	long long l=1;
	for(auto i:a){
		l=l/gcm(l,i)*i;
		if(l>M){
			cout << "0" << endl;
			return 0;
		}
	}
	
	for(int i=0;i<c;i++){
		l*=2;
		if(l>M){
			cout << "0" << endl;
			return 0;
		}
	}
	
	cout << (M/l+1)/2 << endl;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.ComponentModel;
using System.Linq;

namespace Buttons {
	class Program {
		static void Main(string[] args) {
			var inputs = Helper<int>.ReadLine();
			var a = inputs[0];
			var b = inputs[1];

			var result = 0;
			if (a < b) {
				result += b;
				b--;
			} else {
				result += a;
				a--;
			}

			if (a < b) {
				result += b;
				b--;
			} else {
				result += a;
				a--;
			}
			Console.WriteLine(result);
		}
	}

	public static class Helper<T> {
		public static T[] Read(int count) {
			var result = new T[count];
			for (int index = 0; index < count; index++) {
				result[index] = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(Console.ReadLine());
			}
			return result;
		}

		public static T[] ReadLine() {
			var input = Console.ReadLine();
			var inputs = input.Split(' ');
			var result = new T[inputs.Count()];
			for (int index = 0; index < inputs.Count(); index++) {
				result[index] = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(inputs[index]);
			}
			return result;
		}
	}
}


Measured memory_bytes: 15316
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b;
	cin >> a >> b;
	cout << a * b / 2 << '\n';
	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N, K = MAP()
a = LIST()

dp = [[0]*(K+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
	for j in range(K+1):
		if j == 0:
			dp[i+1][j] = 1
		else:
			dp[i+1][j] = (dp[i][j] + dp[i+1][j-1])%mod
			if j-a[i]-1 >= 0:
				dp[i+1][j] -= dp[i][j-a[i]-1]
		dp[i][j] %= mod
print(dp[N][K]%mod)


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

using namespace std;

int max_, min_, n, a, b, c, d, e, r;

int main()
{
    while(true)
    {
        cin >> n;
        
        if(n == 0) { break; }
        
        max_ = -999999999;
        min_ = 999999999;
        
        for(int i = 0; i < n; i++)
        {
            cin >> a >> b >> c >> d >> e;
            
            r = a + b + c + d + e;
            
            max_ = max(max_, r);
            min_ = min(min_, r);
        }
        
        cout << max_ << ' ' << min_ << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2996
import java.util.*;
import java.io.*;
public class Main {

	static Scanner inp= new Scanner(System.in);
	static PrintWriter out= new PrintWriter(System.out);
	public static void main(String args[]) {		    	
		n=inp.nextInt();
		m=inp.nextInt();
		int INF=1_000_000_0;
		int x1=inp.nextInt()-1;
		int y1=inp.nextInt()-1;
		int x2=inp.nextInt()-1;
		int y2=inp.nextInt()-1;
		s=new char[n][m];
		int dp[][]=new int[n][m];
		for(int i=0;i<n;i++) {
			Arrays.fill(dp[i], INF);
		}
		for (int y=0; y<n; y++) {
			char[] line=inp.next().toCharArray();
			for (int x=0; x<m; x++) {
				s[y][x]=line[x];
			}
		}
		ArrayDeque<Integer> xs = new ArrayDeque<Integer>();
		ArrayDeque<Integer> ys = new ArrayDeque<Integer>();
		xs.add(x1);
		ys.add(y1);
		dp[x1][y1]=0;
		int dx[]= {1,0,-1,0};
		int dy[]= {0,1,0,-1};
		while(!xs.isEmpty()) {
			int x=xs.removeFirst();
			int y=ys.removeFirst();
			for(int i=0;i<4;i++) {
				int nx=x+dx[i];
				int ny=y+dy[i];
				if(isValid(nx,ny)) {
					if(dp[nx][ny]>dp[x][y]) {
						dp[nx][ny]=dp[x][y];
						xs.addFirst(nx);
						ys.addFirst(ny);
					}
				}
			}
			for(int nx=x-2;nx<=x+2;nx++) {
				for(int ny=y-2;ny<=y+2;ny++) {
					if(isValid(nx,ny)) {
						if(dp[nx][ny]>dp[x][y]+1) {
							dp[nx][ny]=dp[x][y]+1;
							xs.addLast(nx);
							ys.addLast(ny);
						}
					}
				}
			}
		}
		out.println(dp[x2][y2]==INF?-1:dp[x2][y2]);
	   	out.close();
	}

	static int n;
	static int m;
	static char s[][];
	
	//Main
	void main() {
		
		
	}
    
    
    
    static boolean isValid(int i, int j) {
    	if(i<0 || i>=n || j<0 || j>=m || s[i][j]=='#') return false;
    	return true;
    }
		
}


Measured memory_bytes: 65640
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define MAX 10000007
vector<lli>spf(MAX);
void SPF()
{
	lli i,j;
	for(i=0;i<MAX;i++){
		spf[i]=i;
	}
	for(i=2;i<MAX;i++){
		if(spf[i]==i){
			for(j=i*i;j<MAX;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
}
lli fac(lli n){
	map<lli,lli>ma;
	while(n>1){
		ma[spf[n]]++;
		n/=spf[n];
	}
	if(n!=1){
		ma[n]++;
	}
	map<lli,lli>::iterator it;
	lli c=1,b;
	for(it=ma.begin();it!=ma.end();it++){
		b=it->second;
		c=c*(b+1);
	}
	return c;
}
int main()
{
	SPF();
	lli n,i,t=0,a,ans=0;
	cin >> n;
	for(i=1;i<=n;i++){
		a=fac(i);
		a=a*i;
		ans+=a;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 81192
#include <bits/stdc++.h>
using namespace std;
 
#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      cout<<"#x "<<x<<"\n";
#define trace(x,y)  cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          cout<<"\n";


bool SBF(const pair <int,int>&a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair<int,int>& a, const pair<int,int>& b){return a.S<b.S;}


const int maxn = 1e9+7;
int n, k;
int a[100000][3];

void solve(){
     for(int i = 1 ;i < n ; i++){
	     a[i][0] += max(a[i-1][1], a[i-1][2]);
	     a[i][1] += max(a[i-1][2], a[i-1][0]);
	     a[i][2] += max(a[i-1][1], a[i-1][0]);
     }
     cout<<max(a[n-1][1],max(a[n-1][0],a[n-1][2]));
}
int main(){
	cin >> n;
	for(int i = 0 ;i  < n ;i++)cin >> a[i][0]>>a[i][1]>>a[i][2];
	solve();
return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	char x, y;
	cin >> x >> y;

	if (int(x) < int(y))cout << '<' << endl;
	else if(int(x) > int(y))cout << '>' << endl;
	else cout << '=' << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    int n;
    scanf("%d", &n);
    int minNum = 1e9, ans = 0;
    for(int i = 0; i < n; i++){
        int p;
        scanf("%d", &p);
        minNum = min(minNum, p);
        if(minNum == p) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

struct MyStruct
{
	int parent = -1;
	int depth;
	vector<int>ko;
};


signed main() {
	int i, j;
	int n;
	vector<MyStruct>list(100005);


	cin >> n;

	for (i = 0; i < n; i++) {
		int num, num2;
		cin >> num >> num2;

		for (j = 0; j < num2; j++) {
			int num3;
			cin >> num3;
			list[num].ko.push_back(num3);
			list[num3].parent = num;
		}

	}


	for (i = 0; i < n; i++) {
		int cnt = 0;
		int num = list[i].parent;

		while ( num != -1 )
		{
			cnt++;
			num = list[num].parent;
		}

		list[i].depth = cnt;
	}


	for (i = 0; i < n; i++) {
		cout << "node " << i << ": parent = " << list[i].parent << ", depth = " << list[i].depth << ", ";
		if (list[i].parent == -1) {
			cout << "root, [";
			for (j = 0; j < list[i].ko.size(); j++) {
				cout << list[i].ko[j];
				//if (j <= list[i].ko.size() - 2) { cout << ",g "; }
				if (j <= (int)list[i].ko.size() - 2) { cout << ", "; }
				//if (j + 2 <= list[i].ko.size()) { cout << ",g "; }
				//if (j <= (list[i].ko.size()) - 2) { cout << ",g "; }
			}
			cout << "]" << endl;
		}
		else if (list[i].ko.size() >= 1) {
			cout << "internal node, [";
			for (j = 0; j < list[i].ko.size(); j++) {
				cout << list[i].ko[j];
				if (j <= (int)list[i].ko.size() - 2) { cout << ", "; }
			}
			cout << "]" << endl;
		}
		else if (list[i].ko.size() == 0) {
			cout << "leaf, []" << endl;
		}

	}


	getchar();
	getchar();
	return 0;
}


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

set<char> digits;

bool check(int n) {
	stringstream ss;
	ss << n;
	string s = ss.str();
	for (int i = 0; i < s.size(); i++) {
		if(digits.count(s[i])) return 1;
	}
	return 0;
}

int main() {
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n, k; cin >> n >> k;
	for (int i = 0; i < k; i++) {
		char c; cin >> c;
		digits.insert(c);
	}
	while(check(n)) n++;
	cout << n << '\n';
}


Measured memory_bytes: 384
a=input()
a=int(a)
b=input()
b=b.split()

import numpy as np

c=np.arange(int(b[0]),int(b[1])+1)
z=0
for x in c:
  if x%a==0:
    z=z+1

if z==0:
  print("NG")
else:
  print("OK")


Measured memory_bytes: 27104
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        mut a:[i64;4],
    }
    let mut ans = -INF;

    for i in 0..2 {
        for j in 2..4 {
            ans = max(ans, a[i] * a[j])
        }
    }
    println!("{}", ans);
}
const INF: i64 = 1 << 60;


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,R;cin>>N>>R;
  if(N>=10){
    cout <<R<<endl;
  }else{
    cout <<R+100*(10-N)<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int a,b,c,d,n,k;
	
	while(scanf("%d",&n)!=EOF){
		k=0;
		for(a=0;a<=9&&a<=n;a++)
			for(b=0;b<=9&&a+b<=n;b++)
				for(c=0;c<=9&&a+b+c<=n;c++)
					if(n-a-b-c<=9)
						k++;
		printf("%d\n",k);
	}
	//for(i=0;i<=1000000000;i++);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define MOD 998244353
typedef long long ll;

using namespace std;

int n, a[200000], mxv;
ll cnt[1000001], sum[1000001], diff[1000001], ans;

ll add(ll x, ll y)
{
    return (x+y)%MOD;
}

ll sub(ll x, ll y)
{
    return (x-y+MOD)%MOD;
}

ll mul(ll x, ll y)
{
    return (x*y)%MOD;
}

ll exp(ll a, int b)
{
    if(b==0)
        return 1;
    ll k = exp(a,b/2);
    if(b%2==1)
        return mul(a,mul(k,k));
    else
        return mul(k,k);
}

ll divide(ll x, ll y)
{
    return (x*exp(y,MOD-2))%MOD;
}

int main()
{
    cin >> n;
    for(int i = 0; i<n; i++)
        cin >> a[i];
    for(int i = 0; i<n; i++)
        cnt[a[i]]++, mxv = max(mxv,a[i]);
    for(int i = 1; i<=mxv; i++)
        for(ll j = 0; j<=mxv; j+=i)
            sum[i] = add(sum[i],mul(cnt[j],j)), diff[i] = add(diff[i],mul(cnt[j],mul(j,j)));
    for(int i = 1; i<=mxv; i++)
        sum[i] = divide(sub(mul(sum[i],sum[i]),diff[i]),ll(2));
    for(int i = mxv; i>=1; i--)
        for(int j = 2*i; j<=mxv; j+=i)
            sum[i] = sub(sum[i],sum[j]);
    for(ll i = 1; i<=mxv; i++)
        ans = add(ans,divide(sum[i],i));
    cout << ans << endl;
}


Measured memory_bytes: 24448
/* 
    
*/ 
#include <bits/stdc++.h>
#define md(x, y)  ((x + y) >> 1)
#define ls(x)      (x << 1)
#define rs(x)      (x << 1 | 1)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll INF = 5e18;
ll T, n, S[5], c[5];            //S[]是代价，c[]是金额
map<ll, ll> mp;
ll f(ll x)
{
    if(x == 0)  return 0;
    if(x == 1)  return S[4];
    if(mp[x])   return mp[x];
    ll ret = INF;
    if(ret / S[4] > x) ret = S[4] * x;  //如果直接ret = S[4] * x 会爆LL
    for(int i = 1; i <= 3; i++)
    {
        if(x % c[i] == 0)
            ret = min(ret, f(x / c[i]) + S[i]);
        else 
        {
            ll up = x / c[i] * c[i];                   //向下
            ll co = (x - up) * S[4];
            ret = min(ret, f(up / c[i]) + S[i] + co);
            up = (x / c[i] + 1) * c[i];
            co = (up - x) * S[4];
            ret = min(ret, f(up / c[i]) + S[i] + co);
        }
    }
    return mp[x] = ret;
}

int main()
{
    c[1] = 2, c[2] = 3, c[3] = 5;
    cin >> T;
    while(T--)
    {
        mp.clear();
        cin >> n >> S[1] >> S[2] >> S[3] >> S[4];
        cout << f(n) << endl;
    }   
    return 0;
}

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

using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int rcnt = 0, bcnt = 0;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'R') {
			rcnt++;
		}
		else if(S[i] == 'B'){
			bcnt++;
		}
	}

	if (rcnt > bcnt) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import statistics

N = int(input())
AList = []
BList = []
for i in range(N):
    A, B = map(int, input().split())
    AList.append(A)
    BList.append(B)
    
Amid = statistics.median(AList)
Bmid = statistics.median(BList)

if N % 2 != 0:
    result = int(Bmid - Amid + 1)
else:
    result = int((Bmid - Amid) * 2 + 1)

print(result)
    

Measured memory_bytes: 107756
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  string s; int k;
  cin >> s >> k;
  vector<string> v;
  
  rep(i,s.size()){
    for(int j = 1; j <= 5; j++){
      if(i+j > s.size()) break;
      v.push_back(s.substr(i,j));
    }
  }
  
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v[k-1];
  
  
  return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
ll GCD(ll x,ll y){return y==0? x:GCD(y,x%y);}
ll max(ll x,ll y){return x<y?y:x;}
int main(void){
	int N,i;
	scanf("%d",&N);
	ll A,B,K,gcd,m;
	scanf("%lld",&K);
	scanf("%lld %lld",&A,&B);
	gcd = GCD(A,B);
	m = max(A,B);
	for(i=2;i<N;i++){
		scanf("%lld",&A);
		gcd = GCD(gcd,A);
		m = max(m,A);
	}
	if(K<=m && K%gcd==0)printf("POSSIBLE");
	else printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    d=LI()
    d.sort()
    a=d[N//2-1]
    b=d[N//2]
    ans=b-a
    print(ans)

main()


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

using namespace std;

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

    vector<bool> v(1 << N, true);
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        for(int j = 0; j < A; j++){
            int x;
            bool y;
            cin >> x >> y;
            x--;
            for(int k = 0; k < (1 << N); k++){
                if(k & (1 << i)){
                    if(k & (1 << x)){
                        if(y == 0) v[k] = false;
                    }else{
                        if(y == 1) v[k] = false;
                    }
                }
            }

        }
    }
    int ans = 0;
    for(int i = 0; i < (1 << N); i++){
        if(!v[i]) continue;
        int vv = i;
        int aa = 0;
        while(vv > 0){
            if(vv % 2 == 1) aa++;
            vv /= 2;
        }
        ans = max(ans, aa);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256