akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n,m) for (int i = (int)(n); i < (int)(m); i++)

#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

typedef long long ll;

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

bool isR(string s);

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    vector<bool> v1;
    rep(i,N)
    {
        cin >> v.at(i);
        if(v[i] % 2 == 0)
        {
            if(v[i] % 3 == 0 || v[i] % 5 == 0)
            {
                v1.push_back(true);
            }
            else
            {
                v1.push_back(false);
            }
        }
    }
    bool si = true;
    rep(i,v1.size())
    {
        if(v1[i] == false)
            si = false;
    }

    if(si)
    {
        cout << "APPROVED";
    }
    else
    {
        cout << "DENIED";
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        int[] l = sc.IntArray();

        l = l.OrderByDescending(i => i).ToArray();
        int answer = 0;
        for (int i = 0; i < k; i++)
        {
            answer += l[i];
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13652
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
int bs_cnt_less(vi& A, const int X, bool equal) {
    if (equal) return upper_bound(A.begin(), A.end(), X) - A.begin();
    else return lower_bound(A.begin(), A.end(), X) - A.begin();
}
#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];
    vi B(N); REP(i, N) cin >> B[i];

    int ans = 0;
    REP(k, 29) {
        const int T = 0x01 << k;

        vi a, b;
        REP(i, N) a.push_back(A[i] % (2 * T));
        REP(i, N) b.push_back(B[i] % (2 * T));
        sort(b.begin(), b.end());

        ll cnt = 0;
        REP(i,N) {
            cnt += bs_cnt_less(b, 2 * T - a[i], false) - bs_cnt_less(b, T - a[i], false);
            cnt += bs_cnt_less(b, 4 * T - a[i], false) - bs_cnt_less(b, 3 * T - a[i], false);
        }

        if (cnt % 2 == 1) ans |= 0x01 << k;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4492
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;


pair<int,int> ps[100000+10];

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

  int n, m;
  cin >> n >> m;

  REP(i, n) {
    cin >> ps[i].first >> ps[i].second;
  }
  sort(ps, ps + n);
  ll res = 0;
  int ii = 0;
  priority_queue<int> q;
  for(int i = 1; i <= m; ++i) {
    while(ii < n && ps[ii].first <= i) {
      q.push(ps[ii].second);
      ++ii;
    }
    if(!q.empty()) {
      int cur = q.top(); q.pop();
      res += cur;
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// mint
#include<cstdint>
int64_t const MOD = 998244353;

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};

// fact
template<typename INT>
struct factorial {
  std::vector<INT> fact, ifact;
  void init(int64_t N) {
    fact.resize(N+1); ifact.resize(N+1);
    fact[0] = fact[1] = INT(1);
    for(int i = 2; i <= N; ++i) fact[i] = fact[i-1]*i;
    ifact[N] = fact[N].inv();
    for(int i = N-1; i >= 0; --i) ifact[i] = ifact[i+1]*(i+1);
  }
  INT comb(int64_t n, int64_t k) {
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int const MAXN = 2e5;

using mint = mod_int<MOD>;
factorial<mint> F;

int main() {
  int N, M, K; std::cin >> N >> M >> K;
  F.init(N);
  mint ans;
  for(int i = 0; i <= K; ++i) {
    ans += F.comb(N-1, i)*mint(M-1).pow(N-1-i);
  }
  ans *= M;
  fin(ans.v_);
  return 0;
}


Measured memory_bytes: 6356
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef pair<int,int> P;
 
int par[400005];
int Rank[400005];
P positionx[100005];
P positiony[100005];
int N;

void init(int n){
    for (int i = 0; i< n; i++){
        par[i] = i;
        Rank[i] = 0;
    }
}
int find(int x){
    if(par[x] == x){
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    
    if (Rank[x] < Rank[y]){
        par[x] = y;
    } else {
        par[y] = x;
    }
    if (Rank[x] == Rank[y]) Rank[x]++;
}
bool same(int x, int y) {
    return find(x) == find(y);
}
struct edge { int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

edge es[400005];
int V,E;

long long kruskal(){
    sort(es, es + E,comp);
    init(E);
    long long res = 0;
    for(int i=0;i<E;i++){
        edge e = es[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res += e.cost;
        }
    }
    return res;
}
bool com(const P & e1, const P & e2){
    return e1.second < e2.second;
}
int main(){
    cin >> N;
    for (int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        positionx[i] = P(i,a);
        positiony[i] = P(i,b);
    }
    sort(positionx,positionx + N,com);
    sort(positiony,positiony + N,com);
    P ra = positionx[0];
    P rb = positiony[0];
    for(int i = 1;i<N;i++){
        es[4*(i-1)].cost = positionx[i].second-ra.second;
        es[4*(i-1)].u = ra.first;
        es[4*(i-1)].v = positionx[i].first;
        es[4*i-3].cost = positionx[i].second-ra.second;
        es[4*i-3].v = ra.first;
        es[4*i-3].u = positionx[i].first;
        
        es[4*i-2].cost = positiony[i].second-rb.second;
        es[4*i-2].u = rb.first;
        es[4*i-2].v = positiony[i].first;
        es[4*i-1].cost = positiony[i].second-rb.second;
        es[4*i-1].v = rb.first;
        es[4*i-1].u = positiony[i].first;
        ra = positionx[i];
        rb = positiony[i];
    }
    E = 4*(N-1);
    long long ans = kruskal();
    cout << ans << endl;
    
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define int long long 
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pre(i,a,b) for(int i=(b);i>=(a);i--)
#define ios ios::sync_with_stdio(false),cin.tie(0);
#define pb push_back
#define ps push
#define fi first
#define se second
#define ps push
#define Inf 0x3f3f3f3f3f3f3f3f
#define eps 1e-5
typedef long long ll;
const int N=2e5+5;
const int mod=998244353;
using namespace std;

signed main(){
    ios;
    string s,t;
    int a,b,c;
    cin>>a>>b>>c;

    int k;
    cin>>k;
    if(k<=a){
        cout<<k<<endl;
    }
    else if(k>a&&k<=a+b){
        cout<<a<<endl;
    }
    else{
        cout<<a-(k-(a+b))<<endl;
    }
    return 0;
}

Measured memory_bytes: 3612
n = int(input())
m,a,r,c,h = 0,0,0,0,0
for i in range(n):
    s = input()
    if s[0] == 'M':
        m+=1
    if s[0] == 'A':
        a+=1
    if s[0] == 'R':
        r+=1
    if s[0] == 'C':
        c+=1
    if s[0] == 'H':
        h+=1
ans = 0
if m*a*r != 0:
    ans += m*a*r
if m*a*c != 0:
    ans += m*a*c
if m*a*h != 0:
    ans += m*a*h
if m*r*c != 0:
    ans += m*r*c
if m*r*h != 0:
    ans += m*r*h
if m*c*h != 0:
    ans += m*c*h
if a*r*c != 0:
    ans += a*r*c
if a*r*h != 0:
    ans += a*r*h
if a*c*h != 0:
    ans += a*c*h
if r*c*h != 0:
    ans += r*c*h
print(ans)

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

int par(int i){
	return i/2;
}
int lef(int i){
	return i*2;
}
int right(int i){
	return i*2 + 1;
}

int main(){
	int H;
	vector<int> data(N);
	cin >> H;
	for(int i=1;i<=H;i++) cin >> data.at(i);
	
	for(int i=1;i<=H;i++){
		cout << "node " << i << ": key = " << data.at(i) << ", ";
		if(par(i)>=1) cout << "parent key = " << data.at(par(i)) << ", ";
		if(lef(i)<=H) cout << "left key = " << data.at(lef(i)) << ", ";
		if(right(i)<=H) cout << "right key = " << data.at(right(i)) << ", ";
		cout << endl;
	}
}


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

int main() {
    int n;
    cin>>n;
    string str;
    cin>>str;
    char x = str[0];
    int cnt = 0;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(str[i] == x){
            cnt++;
            continue;
        }else{
            ans++;
            x = str[i];
            cnt = 1;
        }
    }
    ans++;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,k,i,ans=0;
  cin>>n>>k;
  ll h[n];
  for(i=0;i<n;i++) 
  {
    cin>>h[i];
    if(h[i]>=k) ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
A = list(map(int,input().split()))
b = ""
inv = 1
import collections
b = collections.deque()
for i in range(n):
    a = A[i]
    if inv ==1:
        b.append(a)
    else:
        b.appendleft(a)
    inv *=-1
if inv ==1:
    print(*b)
else:
    print(*reversed(b))


Measured memory_bytes: 26020
N = int(input())
A = list(map(int, input().split()))
f = [[a, -1] for a in A]
lim = 1<<N
for i in range(N):
    bit = 1<<i
    j = 0
    while j < lim:
        j |= bit
        a, b = f[j]
        c, d = f[j^bit]
        if a < c:
            f[j][0] = c
            f[j][1] = d if d>a else a
        elif b < c:
            f[j][1] = c
        j += 1
ans = sum(f[1])
Ans = [ans]
for a, b in f[2:]:
    s = a+b
    if s > ans:
        ans = s
    Ans.append(ans)
print("\n".join(map(str, Ans)))


Measured memory_bytes: 73136
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace


------------------
-- #   Read   # --
------------------

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    [x,y] <- r'
    putStrLn $ if odd y then "No"
        else let y' = div y 2
        in   if ceiling(y'`d`2) <= x && x <= y' then "Yes" else "No"


d :: Int -> Int -> Double
d x y = fromIntegral x / fromIntegral y


Measured memory_bytes: 3776
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	char[] o = sc.next().toCharArray();
      	char[] e = sc.next().toCharArray();
      	String s = "";	
      
      	for(int i = 0; i < e.length; i++){
        	s += String.valueOf(o[i]);
          	s += String.valueOf(e[i]);
        }
      	if(o.length!=e.length) s += String.valueOf(o[o.length-1]);
      	System.out.println(s);
    }
}

Measured memory_bytes: 39312
#include <cstdio>
#include <cstring>
#define HW_MAX 300

void
set_line(char* s, int w)
{
  std::memset(s, '#', w);
  s[w] = '\0';
  return;
}

void
set_inner_line(char* s, int w)
{
  s[0] = '#';
  std::memset(s + 1, '.', w - 2);
  s[w - 1] = '#';
  s[w] = '\0';
  return;
}

int
main(void)
{
  int h, w, i;
  char s0[HW_MAX + 1], s1[HW_MAX + 1];
  
  while (std::scanf("%d %d", &h, &w) != EOF) {
    if (h == 0 && w == 0) {
      break;
    }

    set_line(s0, w);
    set_inner_line(s1, w);

    std::printf("%s\n", s0);
    for (i = 0; i < h - 2; i++) {
      std::printf("%s\n", s1);
    }
    std::printf("%s\n", s0);
    std::printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2572
# D - Score Attack
import sys
sys.setrecursionlimit(10 ** 9)

import numpy as np
from heapq import heappush, heappop

N, M, = map(int, input().split())
graph = [[] for _ in range(N+1)] # graph[0]は使わない

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))

def dijkstra(start, c):
    INF = float('inf')
    dist = [-INF] * (N+1) # dist[0]は使わない
    dist[start] = 0
    que = [(start, 0, c)]
    while que:
        place, score, count = heappop(que) # placeは現在地
        if score < dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue
            continue
        for next_node, weight in graph[place]:
            score2 = score + weight
            if next_node == N and count > 1000: # いくらでも大きくなる場合
                print('inf')
                exit()
            if dist[next_node] < score2: # 点数が良くなるなら、データを更新
                dist[next_node] = score2
                heappush(que, (next_node, score2, count+1))
    return dist

d1 = np.array(dijkstra(1, 0))
print(int(d1[N]))

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

int main (){
	int n, k;
	scanf("%d%d", &n, &k);
	long long ans = n / k;
	ans = ans * ans * ans;
	if(!(k & 1)){
		long long t = n / (k / 2) - n / k;
		ans += t * t * t;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define endl "\n"
    #define space " "
    #define ll long long int
    #define vl vector<ll>
    #define vvl vector < vll >
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define vpl vector < pll >
    #define mod 1000000007
    #define pi 3.1415926535897932384626433
    #define inf 1000000000000000001;
    #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y) 
    #define mem(a,val) memset(a,val,sizeof(a))
    #define pb push_back
    #define f first
    #define s second
    
    void solve()
    {
        string s; cin>>s;
        int n = s.length();
        if(s[n-1]!='s') s+='s';
        else s = s + 'e' + 's';
        cout<<s;
    }

    signed main()
    {

    fast;
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

    ll T=1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
    }


Measured memory_bytes: 3644
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer>
inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar()) init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 0, INF = 1e9;

int main() {
	int n = read<int>(), k = read<int>();
	int res = (n - 1) * (n - 2) / 2;
	if (k > res) {
		puts("-1");
		return 0;
	}
	int m = n - 1 + res - k;
	cout << m << endl;
	rep (i, 2, n) printf("1 %d\n", i);
	int cnt = res - k;
	if (cnt == 0) return 0;
	rep (i, 2, n) {
		rep (j, i + 1, n) {
			printf("%d %d\n", i, j);
			--cnt;
			if (cnt == 0) break;
		}
		if (cnt == 0) break;
	}
	return 0;
}



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

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i =0; i < N; i++){
        cin >> L.at(i);
    }
    sort(L.begin(),L.end());
    long long ans = 0;
    for(int i =0; i < N - 2; i++){
        for(int j = i + 1; j < N - 1; j++){
            int sum = L[i] + L[j];
            int u = N - 1;
            while(u > j && sum <= L[u]) u--;
            ans += u - j;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int n; cin >> n;
    ll ans = 0;

    for(int i = 1; i < n; i++){
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
require 'set'
loop do
    l = gets.chomp
    break if l == "0 0"
    answer, call = l.split.map {|s| s.split("")}
    hit = answer.zip(call).select {|a| a.inject(:==)}.size
    blow = (Set[*answer] & Set[*call]).size - hit
    puts "#{hit} #{blow}"
end


Measured memory_bytes: 7248
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        ll N, K;
        cin >> N >> K;
        if (K == 1) {
                cout << 0 << endl;
                return 0;
        }

        ll diff = N - K;
        // ll mx = 1 + diff;
        // ll mn = 1;
        cout << diff << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100000];

int main() {
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i), --a[i];
    int cnt = 0;
    forn(i, n) if (a[a[i]] == i) {
        ++cnt;
    }
    cout << cnt / 2 << endl;
    return 0;
}


Measured memory_bytes: 640
A, B = map(int, input().split())

grid = [["#"]*100 for _ in range(50)]
grid += [["."]*100 for _ in range(50)]

ha, wa = divmod(A-1, 50)
for h in range(ha):
  for j in range(50):
    grid[2*h][2*j] = "."
for w in range(wa):
  grid[2*ha][2*w] = "."

hb, wb = divmod(B-1, 50)
for h in range(hb):
  for j in range(50):
    grid[51+2*h][2*j] = "#"
for w in range(wb):
  grid[51+2*hb][2*w] = "#"

print(100, 100)
for G in grid:
  print("".join(G))

Measured memory_bytes: 9292
import math  

N, X = [int(x) for x in input().split()]
Coordinates = [int(x) for x in input().split()]

diff = [abs(x - X) for x in Coordinates]

if len(diff) == 1:
  print(min(diff))
else:
  ans = diff[0]
  for i in range(1, len(diff)):
    ans = math.gcd(ans, diff[i])
  print(ans)

Measured memory_bytes: 20420
// Contest No.: ABC177
// Problem No.: E
// Solver:      Jinmin Goh
// Date:        20200829

#include <cstring>
#include <iostream>
#include <cstdlib>
#include <list>
#include <array>
#include <atomic>
#include <algorithm>
#include <deque>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int AList[200010], BList[200010], parent[200010], parentCnt[200010];

int findParent(int node) {
    if(parent[node] == node) {
        return node;
    }
    parent[node] = findParent(parent[node]);
    return parent[node];
}

void unionFunc(int node1, int node2) {
    int p1 = findParent(node1), p2 = findParent(node2);
    parent[p2] = p1;
    return;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) {
        parent[i] = i;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d %d", &AList[i], &BList[i]);
        unionFunc(AList[i], BList[i]);
    }

    for(int i = 1; i <= n; i++) {
        parentCnt[findParent(i)]++;
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans = max(ans, parentCnt[i]);
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
const string el = "\n";
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
int out(int a){cout << a << el; return 0;}
int out(string s = "NO"){cout << s << el; return 0;}
template <class T>
inline int out(vector<T>&v,string c = " "){
    for(int i = 0; i < v.size(); ++i){
        if(i) cout << c; cout << v[i];
    } cout << el;return 0;
}
signed main(){
    fast_io();
    int N,K; cin >> N >> K;
    cout << min((N % K), K  - (N % K)) <<endl;
}




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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;
    string rs = s;
    reverse(rs.begin(), rs.end());

    deque<char> qs;
    deque<char> qrs;

    for (int i = 0; i < s.size(); i++) qs.push_back(s[i]);
    for (int j = 0; j < rs.size(); j++) qrs.push_back(rs[j]);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            swap(qs, qrs);
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                qs.push_front(c);
                qrs.push_back(c);
            } else {
                qs.push_back(c);
                qrs.push_front(c);
            }
        }
    }
    string ans;
    while (!qs.empty()) {
        ans.push_back(qs.front());
        qs.pop_front();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
#include "bits/stdc++.h"
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;
typedef pair<plint, lint> tlint;
struct edge {
	lint cost;
	lint u, v;
};

template< typename T >
class UnionFind {
public:
	vector <T> par; // 各元の親を表す配列
	vector <T> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(T sz_) : par(sz_), siz(sz_, 1ll) {
		for (T i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(T sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1ll);  // resize だとなぜか初期化されなかった
		for (T i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	T root(T x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(T x, T y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(T x, T y) { // 連結判定
		return root(x) == root(y);
	}

	T size(T x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

lint N, M, A, B;
int main() {
	cin >> N >> M;
	UnionFind<lint> tree(N);
	REP(i, M) {
		cin >> A >> B; A--; B--;
		tree.merge(A, B);
	}
	lint maxv = 0;
	REP(i, N) {
		chmax(maxv, tree.size(i));
	}
	cout << maxv << endk;
}


Measured memory_bytes: 6424
#include <iostream>
#include<algorithm>
using namespace std;
int allsum(int* a,int n){
    int r=0;
    for(int i=0;i<n;i++){
        r=r*10+a[i];
    }
    return r;
}
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int* p=new int[n];
    int* q=new int[n];
    long long int pi=0,qi=0;
    
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    if(allsum(p,n)>allsum(q,n)){swap(p,q);}
    int r=0;
    while(allsum(p,n)<allsum(q,n)){
        next_permutation(p,p+n);
        r++;
    }
    cout<<r;
    
    
    
    delete[]p;
    delete[]q;
    return 0;
}


Measured memory_bytes: 256
#define DivertaPC2019_B
#ifdef DivertaPC2019_B

#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    ll ans = 0;

    vll table(N + 1);
    rep(i, 3001) {
        rep(j, 3001) {
            if (i * R + j * G > N) continue;
            table[i * R + j * G]++;
        }
    }

    rep(i, 3001) {
        rep(j, N + 1) {
            if (i * B + j == N) ans += table[j];
        }
    }

    write(ans);
}

#endif

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int mod = 1e9 + 7; 
int a[maxn];
int b[5];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	long long sum = 1;
	for(int i = 1; i <= n; i++){
		int val = a[i];
		int ans = 0;
		for(int j = 1; j <= 3; j++){
			if(b[j] == val){
				ans++;
			}
		}
		sum = (sum * ans) % mod;
		for(int j = 1; j <= 3; j++){
			if(b[j] == val){
				b[j]++;
				break;
			}
		}
	}
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
double a;
#define pi acos(-1)

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> a;
	cout << fixed << setprecision(10) << 2*pi*a << '\n';
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

struct topological_sort{
    vector<vector<int>> G;
    vector<int> indegree;
    int V;

    topological_sort(int V) : V(V) {G.resize(V); indegree.resize(V);}
    void add_edge(int a, int b) {
        G[a].push_back(b);
        indegree[b]++;
    }
    vector<int> sort() {
        queue<int> q;
        vector<int> sorted;
        for (int i = 0; i < V; i++) if (indegree[i] == 0) q.push(i);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (int i = 0; i < G[v].size(); i++) {
                int u = G[v][i];
                indegree[u]--;
                if (indegree[u] == 0) q.push(u);
            }
            sorted.push_back(v);
        }
        return sorted;
    }
};

int main() {
    int n, m; cin >> n >> m;
    topological_sort ts(n);
    vvint dest(n);
    rep(i,n-1+m) {
        int a, b; cin >> a >> b;
        a--; b--;
        ts.add_edge(a,b);
        dest[b].push_back(a);
    }
    vint res = ts.sort();
    map<int,int> mp;
    rep(i,n) mp[res[i]] = i;
    rep(i,n) {
        if (dest[i].empty()) cout << 0 << endl;
        else {
            set<int> st;
            rep(j,dest[i].size()) st.insert(mp[dest[i][j]]);
            cout << res[*st.rbegin()] + 1 << endl;
        }
    }
}

Measured memory_bytes: 19560
//============================================================================
// Name        : ITP_1_11_A.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

// [0]が上面にある時のサイコロの状態を作成。
// 反時計回り。
int DICE_INDEX[6][4] =
{
		{2,3,5,4},
		{6,3,1,4},
		{6,5,1,2},
		{6,2,1,5},
		{6,4,1,3},
		{5,3,2,4}
};

class Dice
{
public:
	int nums[6];
	int joumen_index;
	int shoumen_index;

public:
	Dice();

	void Rotate(char cmd);
	int GetSideIndex(char LR, int jou, int shou);
};

Dice::Dice()
{
	// サイコロの初期状態
	joumen_index = 1;
	shoumen_index = 2;
}

void Dice::Rotate(char cmd)
{
	int tmp_joumen = 0;
	int tmp_shoumen = 0;

	if(cmd == 'N'){
		tmp_shoumen = 7 - joumen_index;
		tmp_joumen = shoumen_index;
	}
	else if(cmd == 'E'){
		tmp_shoumen = shoumen_index;
		tmp_joumen = GetSideIndex('L', joumen_index, shoumen_index);
	}
	else if(cmd == 'S'){
		tmp_shoumen = joumen_index;
		tmp_joumen = 7 - shoumen_index;
	}
	else if(cmd == 'W'){
		tmp_shoumen = shoumen_index;
		tmp_joumen = GetSideIndex('R', joumen_index, shoumen_index);
	}
	joumen_index = tmp_joumen;
	shoumen_index = tmp_shoumen;
}

int Dice::GetSideIndex(char LR, int jou, int shou)
{
	int res = 0;
	for(int i=0;i<4;i++){
		if(DICE_INDEX[jou-1][i] == shou){
			if(LR == 'L') res = DICE_INDEX[jou-1][(i + 3) % 4];
			if(LR == 'R') res = DICE_INDEX[jou-1][(i + 1) % 4];
		}
	}
	return res;
}

int main()
{
	Dice dice;

	// サイコロ面の数字入力
	for(int i=0;i<6;i++){
		cin >> dice.nums[i];
	}

	// 動かし方
	string cmd;
	cin >> cmd;

	// 動かします。
	for(int c = 0;c < cmd.size();c++){
		dice.Rotate(cmd[c]);
	}

	// 結果
	cout << dice.nums[dice.joumen_index-1] << endl;

	return 0;
}



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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    string s;
    ll k;
    cin >> s >> k;
    int count = 0;
    char num;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1')count++;
        else {
            num = s[i];
            break;
        }
    }
    if(count>=k)COUT(1);
    else COUT(num);
    return 0;
} 

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

int main() {
    string s;
    cin >> s;
    int n_s = s.size();

    bool ans = true;
    if (n_s % 2 != 0) ans = false;
    else rep(i,n_s/2) {
        if (s[2*i] != 'h') ans = false;
        if (s[2*i+1] != 'i') ans = false;
    }
        puts(ans?"Yes":"No");

    return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  
  if(a - b >= 0) cout << "delicious" << endl;
  else if(x >= b - a) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int N,M,P,r=1<<29;
	scanf("%d%d%d",&N,&M,&P);
	vector<int>v(M+1);
	for(int i=0;i<M;i++)scanf("%d",&v[i]);
	v[M]=P;
	M++;
	sort(v.begin(),v.end());
	int idx=distance(v.begin(),lower_bound(v.begin(),v.end(),P));
	for(int i=0;i<M;i++){
		//unused section=v[i]..v[i+1]
		r=min(r,min(
			(v[i]-v[idx]+N)%N+(v[i]-v[(i+1)%M]+N)%N,
			(v[idx]-v[(i+1)%M]+N)%N+(v[i]-v[(i+1)%M]+N)%N
		));
	}
	printf("%d\n",r*100);
}

Measured memory_bytes: 1080
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<set>
using namespace std;
void init(int n);
void unite(int x,int y);
int find(int x);
bool same(int x,int y);

int par[200010]; // ???
int rnk[200010]; // ??±???

/* Union Find ????????? */
void init(int n){
  for(int i=0;i<=n;i++){
    par[i] = i;
    rnk[i] = 0;
  }
}

/* x???????????¨y?????????????????? */
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rnk[x] < rnk[y]){
	  par[x] = y;
	}
	else {
	  par[y] = x;
	}
	if(rnk[x] == rnk[y]) rnk[x]++;
}

/* x????????????????????¢?´¢ */
int find(int x){
  if(par[x] == x){
    return x;
  }
  else {
    return par[x] = find(par[x]);
  }
}

/* x??¨y????????????????????????????????? */
bool same(int x,int y){
  return find(x) == find(y);
}

int main(){
	int n,w,h;
	cin >> n >> w >> h;
	init(n);
	int X[200000],Y[200000],wall = 0;
	memset(X,-1,sizeof(X)); memset(Y,-1,sizeof(Y));
	for(int i=0;i<n;i++){
		int x,y; cin >> x >> y;
		wall |= (x==w) | (x==1) | (y==h) | (y==1);
		if(X[x] < 0) X[x] = i;
		else unite(i,X[x]);
		if(Y[y] < 0) Y[y] = i;
		else unite(i,Y[y]);
	}
	set<int> cnt;
	for(int i=0;i<w+1;i++) if(X[i] >= 0) cnt.insert(find(X[i]));
	if(cnt.size() == 1) cout << n-1 << endl;
	else cout << n-1+(cnt.size()-wall) << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string str[H+2];
  for (int i = 0; i < W + 2; i++) {
  	str[0] += ".";
  	str[H + 1] += ".";
  }
  for (int i = 1; i < H + 1; i++) {
  	cin >> str[i];
    str[i] = "." + str[i] + ".";
  }

  for (int i = 1; i < H + 1; i++) {
	for (int j = 1; j < W + 1; j++) {
      if (str[i][j] == '.') {
        int c = 0;
        if (str[i-1][j-1] == '#') {
          c++;
        }
        if (str[i-1][j] == '#') {
          c++;
        }
        if (str[i-1][j+1] == '#') {
          c++;
        }
        if (str[i][j-1] == '#') {
          c++;
        }
        if (str[i][j+1] == '#') {
          c++;
        }
        if (str[i+1][j-1] == '#') {
          c++;
        }
        if (str[i+1][j] == '#') {
          c++;
        }
        if (str[i+1][j+1] == '#') {
          c++;
        }
        cout << c;
      } else {
        cout << str[i][j];
      }
    }
    cout << endl;
  }
  
}


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

int main(){
	int c=getchar();
	while(!isdigit(c))c=getchar();
	int k=c;
	while(isdigit(c)){
		c=getchar();
		if(k==c){
			cout<<"Bad"<<endl;
			return 0;
		}
		k=c;
	}
	cout<<"Good"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;*/
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef vector<int> vec;
//typedef pair<int,int> pii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define fi first
#define se second
/*#define tupfi(v,i) get<0>(v[i])
#define tupse(v,i) get<1>(v[i])
#define tupth(v,i) get<2>(v[i])
#define mt make_tuple */
#define pb push_back
#define mp make_pair
#define rrep(i,a,b) for(int i = (a-1); i >= b; i--)
#define endl "\n"
typedef long long ll;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); 
	ll t;t=1;
	while(t--){
			int n,m;
			cin>>n>>m;
			int a[n];
			int sum=0;
			rep(i,0,n){cin>>a[i];sum+=a[i];}
			float val=(1.0/(4*m*1.0))*(sum*1.0);
			sort(a,a+n);
			int count=0;
			rep(i,0,n){
				if(a[i]>=val)count++;
			}
			if(count>=m)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
	}
	return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

const int MN = 200005;

using ll = long long;

ll a[MN];
ll b[MN];
int n;
queue<int> q;

void trypush(int i){
	if((b[i]>b[(i-1+n)%n]+b[(i+1)%n])&&b[i]>a[i])q.push(i);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0; i<n; ++i)cin>>a[i];
	for(int i=0; i<n; ++i)cin>>b[i];
	for(int i=0; i<n; ++i){
		trypush(i);
	}
	ll res=0;
	while(!q.empty()){
		int i=q.front();
		q.pop();
		ll sum = b[(i+1)%n]+b[(i+n-1)%n];
		ll hm = (b[i]-a[i])/sum;
		res+=hm;
		b[i]-=sum*hm;
		trypush((i+1)%n);
		trypush((i-1+n)%n);
	}
	for(int i=0; i<n; ++i){
		if(b[i]!=a[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout <<res<<endl;
	return 0;
}


Measured memory_bytes: 3840
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int L=sc.nextInt();
		String[] S=new String[N];
		String ans="";
		
		for(int i=0;i<N;i++) {
			S[i]=sc.next();
		}
		
		Arrays.sort(S);
		
		for(int i=0;i<N;i++)
			ans+=S[i];
		
		System.out.println(ans);
		
		sc.close();
	}
}

Measured memory_bytes: 24148
#include <bits/stdc++.h>
#define N 500001

using namespace std;

int n, ans = 0x7fffffff;
int A[N], B[N];
char a[N];

int main() {
  scanf("%d", &n);
  scanf("%s", a + 1);

  for (int i = 1; i <= n; ++i) B[i] = a[i] == '.' ? B[i - 1] + 1 : B[i - 1];
  for (int i = n; i >= 1; --i) A[i] = a[i] == '#' ? A[i + 1] + 1 : A[i + 1];

  for (int i = 0; i <= n; ++i)
    ans = min(ans, abs(i - B[i]) + abs(n - i - A[i + 1]));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int n,f[100010][25];
vector<int> a[100010];
inline void dp(int i,int l)
{
    int j,k;
    for(j=0;j<a[i].size();j++)
      if(a[i][j]!=l)
        {
         dp(a[i][j],i);
         for(k=1;k<=20;k++)
           f[i][k]+=f[a[i][j]][k];
        }
    for(j=20;j>0;j--)
      if(f[i][j]>1)
        break;
    for(j++;f[i][j];j++);
    f[i][j]=1;
    for(j--;j>0;j--)
      f[i][j]=0;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	  {
       scanf("%d%d",&j,&k);
       a[j].push_back(k);
       a[k].push_back(j);
      }
    dp(1,0);
    for(i=20;!f[1][i];i--);
    printf("%d\n",i-1);
	return 0;
}


Measured memory_bytes: 19456
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

tuple<ll, ll, ll> solve(ll N) {
  repr (n, 1, 3501) {
    repr (h, 1, 3501) {
      ld den = 4 * h * n - N * h - N * n;
      ld num = N * n * h;
      if (den == 0) continue;
      ld w = num / den;
      if (w > 0 && w == (ll) w) {
        return make_tuple(n, w, h);
      }
    }
  }
  return make_tuple(-1, -1, -1);
}

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ld N;
  cin >> N;
  ll h, n, w;
  tie(h, n, w) = solve(N);
  cout << h << " " << n << " " << w << "\n";
}

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

int main()
{
    char s[100]; int i,j,c=1,f=0,a[10];
    cin>>s;
    for(i=0;i<4;i++)
        a[i]=0;
    for(i=0;s[i]!='\0';i++)
    {
        if(s[i]=='1')
            continue;
        for(j=i+1;s[j]!='\0';j++)
        {
            if(s[i]==s[j])
            {
                s[j]='1';
                c++;
                if(c>2)
                    {
                        f=1;
                        break;
                    }
            }
        }
        if(f==1)
            break;
       a[i]=c;
       c=1;
    }
    c=0;
    for(i=0;i<4;i++)
    {
        if(a[i]==2)
            c++;
    }
    if(c==2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    string s;
    cin >> s;

    for (int i=0; i<s.size(); ++i)
        if (s[i] == ',')
            s[i] = ' ';

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


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
  ll N, K; cin >> N >> K;
  if(N%K==0) {
    cout << 0 << endl;
    return 0;
  }
  ll res = N%K;
  res = min(abs(res-K), res);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256