akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[x, y, z] <- readIntToList <$> BS.getLine
	putStr . show $ z
	putStr " "
	putStr . show $ x
	putStr " "
	putStrLn . show $ y


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

int main() {
  int n, ans = 0, rcnt = 0;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      rcnt++;
    }
  }
  for (int i = 0; i < rcnt; i++) {
    if (s[i] == 'W') {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int siz[100005],dep[100005],p[100005];
vector <int> vec[100005];
void dfs(int pos,int fa)
{siz[pos]=1;
for (int i=0;i<vec[pos].size();i++)
{int v=vec[pos][i];
if (v!=fa)
{p[v]=pos;
dep[v]=dep[pos]+1;dfs(v,pos);
siz[pos]+=siz[v];
}
}
}
int main (){
	int u,v,n,i;
	scanf ("%d",&n);
	for (i=1;i<n;i++)
	{scanf ("%d%d",&u,&v);
	vec[u].push_back(v);
	vec[v].push_back(u);
	}
	dep[1]=0;dfs(1,0);
	int stp=(dep[n]-1)/2,tar=n;
	while (stp--) {n=p[n];}
	int num=siz[n];
	if (num*2>=tar) {printf ("Snuke\n");}
	else {printf ("Fennec\n");}
	return 0;
}
	
	

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

string a[55], b[55], c[55];
signed main(void)
{
  while(true) {
    int n, len = 0;
    cin >> n;
    if(!n) break;
    REP(i, n) b[i] = "";
    REP(i, n) {
      cin >> a[i];
      REP(j, a[i].size()) {
        if(!j) b[i] += a[i][j];
        if((a[i][j] == 'a' || a[i][j] == 'i' || a[i][j] == 'u' || a[i][j] == 'e' || a[i][j] == 'o') && (j < a[i].size()-1)) b[i] += a[i][j+1];
      }
      len = max(len, (int)b[i].size());
    }
    bool f = true;
    FOR(i, 1, len+1) {
      set<string> st;
      REP(j, n) {
        st.insert(b[j].substr(0, i));
      }
      if((int)st.size() == n) {
        cout << i << endl;
        f = false;
        break;
      }
    }
    if(f) cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3116
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Xi Lin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int x = 0, r = 0;
            for (int i = 0; i < n; ++i) {
                if (s.charAt(i) == 'I') ++x;
                else --x;
                if (x > r) r = x;
            }
            out.println(r);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define Bye return 0
const int MAX = 1e9+7;

void solve(){
    int n, res = 1; cin>>n;
    
    int a[n+1];
    memset(a, 0, sizeof a);
    bool no_solution = false; 

    for (int i=1; i<=n; i++){ int e; cin>>e; a[e]++;}
    int counter = (n%2^0) ? (n-1)/2 :  n/2;
    for (int i=1; i<=counter; i++) res = (res*2)%MAX;
    bool isValid = false;

    for (int i=0; i<n; i+=2){
        isValid += (i+2<n && a[i+2]^2 && n%2^0) ? true : false;
        isValid += (i+1<=n-1 && a[i+1]^2 && !(n%2^0)) ? true : false;
    }
    
    cout<<((!isValid) ? res : 0)<<endl;
}

int main()
{
    solve();
    Bye;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

const int inf = 0x3f3f3f3f;
int cost[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
int dp[100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	vector<int> digs(m);
	rep(i, 0, m) read(digs[i]);
	sort(all(digs));
	reverse(all(digs));

	rep(i, 0, n) dp[i] = -inf;

	dp[n] = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (int d : digs) if (i + cost[d] <= n)
			chmax(dp[i], dp[i + cost[d]] + 1);
	}

	vector<int> ans;
	for (int i = 0; i < n;) {
		for (int d : digs) if (dp[i] == dp[i + cost[d]] + 1 && i + cost[d] <= n)
		{ 
			ans.push_back(d); i += cost[d]; break; 
		}
	}

	for (int d : ans) cout << d;
	cout << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main()
{
	char str[10000] = { 0 }, str2[10000];
	int i, m, n, j, cnt1=0, cnt2=0;
	while (scanf("%s", str) != EOF){
		cnt1 = 0;
		cnt2 = 0;
		n = strlen(str);
		for (i = 0; i < n; i++) {
			if (str[i] == 'J'&&str[i + 1] == 'O'&&str[i + 2] == 'I') {
				cnt1++;
			}
			if (str[i] == 'I'&&str[i + 1] == 'O'&&str[i + 2] == 'I') {
				cnt2++;
			}
		}
		printf("%d\n%d\n", cnt1, cnt2);
	}
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  ll n, k;
  cin >> n >> k;
  const ll MOD = 1e9 + 7;
  vector <ll> arr(n);
  const int MX = 2010;
  vector <int> cnt(MX, 0);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
  }
  vector <int> vis(MX, 0);
  ll ans = 0;
  for (int j = 0; j < n; j++) {
    ll x = 0;
    ll gt = 0;
    for (int i = arr[j] + 1; i < MX; i++) {
      x += vis[i];
      gt += cnt[i];
    }
    ll add1 = (k * x) % MOD;
    ll add2 = ((k - 1) * k / 2) % MOD;
    ll add = (add1 + gt * add2) % MOD;
    ans = (ans + add) % MOD;
    vis[arr[j]]++;
  }
  cout << ans << '\n';
  return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,t,ans;
int main() {
	cin>>a>>b>>c>>t;
	for(int i=0; i<=a; i++)
		for(int j=0; j<=b; j++)
			for(int k=0; k<=c; k++)
				if(i*500+j*100+k*50==t)ans++;
	cout<<ans;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//↑templete
int main() {
	ll N, K;
	cin>>N>>K;
	vll A, F;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	for(int i=0;i<N;i++){
		int f;
		cin>>f;
		F.pb(f);
	}
	sort(A.begin(), A.end());
	sort(F.begin(), F.end(), greater<ll>());
	ll OK=INFLL, NG=-1;
	while(OK-NG>1){
		ll score=(OK+NG)/2;
		//cout<<"score "<<score<<endl;
		ll train=0;
		//scoreを達成できるか？
		for(int i=0;i<N;i++){
			ll now=A[i]*F[i];
			if(now>score){
				//cout<<A[i]<<" "<<F[i]<<endl;
				train+=(now-score+F[i]-1)/F[i];
				//cout<<(now-score+F[i]-1)<<" "<<F[i]<<endl;;
			}
		}
		//cout<<"train "<<train<<endl;
		if(train<=K)
			OK=score;
		else
			NG=score;
	}
	cout<<OK<<endl;
	return 0;
}

Measured memory_bytes: 4848
#include <stdio.h>
#include <string.h>

int main(void){
    
    int i,j,k=0,l=0;
    int len;
    int apple_c,peach_c;
    char data[2000];
    char apple[]={"apple"};
    char peach[]={"peach"};
    
    fgets(data,sizeof(data),stdin);
    
    len=strlen(data);
    
    for(i=0;i<len-5;i++){
        k=0;
        apple_c=0;
        for(j=i;j<i+6;j++){
            if(data[j]==apple[k]){
                apple_c++;
                k++;
            }else{
                break;
            }
        }
        k=0;
        if(apple_c==5){
            for(j=i;j<i+5;j++){
                data[j]=peach[k];
                k++;
            }
            continue;
        }
        l=0;
        peach_c=0;
        for(j=i;j<i+6;j++){
            if(data[j]==peach[l]){
                peach_c++;
                l++;
            }
            else{
                break;
            }
        }
        l=0;
        if(peach_c==5){
            for(j=i;j<i+5;j++){
                data[j]=apple[l];
                l++;
            }
        }
    }
    printf("%s",data);
    return(0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
string f(string S, string T){
  set<char> A;
  for (int i = 0; i < S.size(); i++){
    A.insert(S[i]);
  }
  for (int i = 0; i < T.size(); i++){
    A.insert(T[i]);
  }
  string ans;
  for (auto c : A){
    ans += c;
  }
  return ans;
}
vector<string> segtree(vector<char> &A){
  int N = 1;
  while (N < A.size()){
    N = N * 2;
  }
  vector<string> ST(N * 2 - 1);
  for (int i = 0; i < A.size(); i++){
    ST[i + N - 1] = A[i];
  }
  for (int i = A.size() + N - 1; i < N * 2 - 1; i++){
    ST[i] = "";
  }
  for (int i = N - 2; i >= 0; i--){
    ST[i] = f(ST[i * 2 + 1], ST[i * 2 + 2]);
  }
  return ST;
}
void segtree_update(vector<string> &ST, int i, char x){
  int N = (ST.size() + 1) / 2;
  i = i + N - 1;
  ST[i] = x;
  while (i > 0){
    i = (i - 1) / 2;
    ST[i] = f(ST[i * 2 + 1], ST[i * 2 + 2]);
  }
  return;
}
string segtree_query(vector<string> &ST, int x, int y, int i, int L, int R){
  if (y <= L || R <= x){
    return "";
  } else if (x <= L && R <= y){
    return ST[i];
  } else {
    int M = (L + R) / 2;
    string A = segtree_query(ST, x, y, i * 2 + 1, L, M);
    string B = segtree_query(ST, x, y, i * 2 + 2, M, R);
    return f(A, B);
  }
}
int main(){
  int N;
  cin >> N;
  vector<char> S(N);
  for (int i = 0; i < N; i++){
    cin >> S[i];
  }
  int Q;
  cin >> Q;
  vector<string> ST;
  ST = segtree(S);
  int L = (ST.size() + 1) / 2;
  for (int i = 0; i < Q; i++){
    int q;
    cin >> q;
    if (q == 1){
      int i;
      cin >> i;
      char c;
      cin >> c;
      i--;
      segtree_update(ST, i, c);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      string ans = segtree_query(ST, l, r, 0, 0, L);
      cout << ans.size() << endl;
    }
  }
}

Measured memory_bytes: 59392
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
ans=X[0]
for i in range(n[0]-1):
    ans=gcd(ans,X[i])
print(ans)

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String sd = reverse(scan.next());
		String t = reverse(scan.next());
		scan.close();
		
		for(int i = 0; i < sd.length(); i++) {
			for(int j = 0; j < t.length() && i+j < sd.length(); j++) {
				if(sd.charAt(i+j)!=t.charAt(j) && sd.charAt(i+j)!='?') break;
				
				if(j == t.length()-1) {
					System.out.println(reverse(makeS(sd,t,i)));
					return;
				}
			}
		}
		
		System.out.println("UNRESTORABLE");
	}

	public static String makeS(String sd, String t, int i) {
		char[] ans = new char[sd.length()];
		for(int j = 0; j < i; j++)
			ans[j] = sd.charAt(j) == '?' ? 'a' : sd.charAt(j);
		
		for(int j = 0; j < t.length(); j++) 
			ans[i+j] = t.charAt(j);
		
		for(int j = t.length()+i; j < sd.length(); j++)
			ans[j] = sd.charAt(j) == '?' ? 'a' : sd.charAt(j);
		
		return new String(ans);
	}
	
	public static String reverse(String s) {
		char[] ans = new char[s.length()];
		for(int i = 0; i < s.length(); i++)
			ans[i] = s.charAt(s.length()-i-1);
		
		return new String(ans);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int X; cin >> X;
    int ans=0;
    for (int i=X;i>=1;i--){
        for (int j=1;j<=1000;j++){
            for (int k=2;k<=10;k++){
                if (pow(j,k)==i) {
                    cout << i << endl;
                    return 0;
                }
            }
        }
    }
} 

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, cou[5], ans;
std::string S[112345];

int main()
{
	in >> N;
	rep(i, N) in >> S[i];
	rep(i, N)
	{
		auto ss = S[i][0];
		if (ss == 'M') ++cou[0];
		if (ss == 'A') ++cou[1];
		if (ss == 'R') ++cou[2];
		if (ss == 'C') ++cou[3];
		if (ss == 'H') ++cou[4];
	}
	int tmp[] = { 0,1,2,3,4 };
	int b1 = 0, b2 = 0, b3 = 0;
	do
	{
		if (tmp[0] == b1 && tmp[1] == b2 && tmp[2] == b3) continue;
		ans += cou[tmp[0]] * cou[tmp[1]] * cou[tmp[2]];
		b1 = tmp[0], b2 = tmp[1], b3 = tmp[2];
	} while (std::next_permutation(tmp, tmp + 5));
	out << ans / 6LL << std::endl;
	return 0;
}

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

int n;
long long a[200055];
char buff[55];
int cnt[25][25];

int main() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        scanf("%s", buff);

        int dot = 0;
        int m = strlen(buff);

        while (dot < m && buff[dot] != '.') dot++;

        if (dot == m) buff[m++] = '.';

        while (m - dot <= 9) {
            buff[m++] = '0';
        }

        long long x = 0;
        long long y = 0;

        for (int j = 0; j < dot; j++) x = x * 10 + buff[j] - '0';
        for (int j = dot + 1; j < m; j++) y = y * 10 + buff[j] - '0';

        a[i] = x * (long long)1e9 + y;
     //   cerr << i << " " << a[i] << endl;
    }

    int have = 0;
    long long res = 0;

    for (int i = 0; i < n; i++) {
        int p = 0, q = 0;

        while (a[i] % 5 == 0) {
            a[i] /= 5;
            p++;
        }

        while (a[i] % 2 == 0) {
            a[i] /= 2;
            q++;
        }

        p = min(p, 18);
        q = min(q, 18);

        for (int x = 0; x <= 18; x++) for (int y = 0; y <= 18; y++) {
            if (x + p >= 18 && y + q >= 18) {
                res += cnt[x][y];
            }
        }

        cnt[p][q]++;
        have++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5220
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]int, n)
	for i := range s {
		fmt.Scan(&s[i])
	}

	cnt := bubble_sort(s)
	for i, e := range s {
		fmt.Print(e)
		if i < n-1 {
			fmt.Print(" ")
		} else {
			fmt.Println()
		}
	}
	fmt.Println(cnt)
}

func bubble_sort(s []int) int {
	if cnt := step(s); cnt > 0 {
		return cnt + bubble_sort(s)
	}
	return 0
}

func step(s []int) int {
	if len(s) < 2 {
		return 0
	}

	var cnt int
	s[0], s[1], cnt = swap(s[0], s[1])
	return cnt + step(s[1:])
}

func swap(a, b int) (int, int, int) {
	if a > b {
		return b, a, 1
	}
	return a, b, 0
}



Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;


int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    ll ans = INF;
    for(int bit=0; bit<(1<<n); bit++){
        if(__builtin_popcount(bit) < k) continue;
        ll maxv = 0;
        ll sum = 0;
        rep(i, n){
            if(((bit>>i) & 1) && v[i] <= maxv){
                sum += (maxv - v[i] + 1);
                maxv++;
            }
            chmax(maxv, v[i]);
        }
        chmin(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let (N,M,X) = readTriple int int int ()
let C = Array.zeroCreate N
let A = Array2D.zeroCreate N M
for i in 0..(N-1) do
  let cin = reads int ()
  C.[i] <- cin.[0]
  Array.tail cin |> Array.iteri (fun j x -> A.[i,j]<-x)

seq {
  for n in 0..((1<<<N)-1) do
    let mutable cost = 0
    let st = Array.create M 0
    for i in 0..(N-1) do
      if (n &&& (1<<<i))<>0 then do
        cost <- cost + C.[i]
        for j in 0..(M-1) do
          st.[j]<-st.[j]+A.[i,j]
    if
      st |> Array.forall (fun x -> x>=X)
    then
      yield cost
}
|> Seq.fold (
  fun st c ->
    match st with
    | Some v -> Some (min v c)
    | None -> Some c
) None
|> function
| Some v -> v
| None -> -1
|> printfn "%d"


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

void Main()
{
    // long n = pow<long>(1000, 5) - pow<long>(999, 5);
    // cout << n << endl;
    long x;
    cin >> x;
    long range = 1000;
    for (long i = -range; i < range; i++)
    {
        for (long j = -range; j < range; j++)
        {
            long a = i*i;
            a = a*a*i;
            long b = j*j;
            b = b*b*j;
            long n = a - b;
            if(x == n){
                cout << i << " " << j << endl;
                return;
            }
        }
        
    }
    cout << "failed" << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,l;
    scanf("%d",&n);
    l=0;
    for(i=1;i<=n;i++){
       l=(l*10+7)%n;
       if(l==0){
         printf("%d\n",i);
         return 0;
       }
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 3812
#include <stdio.h>

int main(){
    int n, r, p, c, i;
    
    for(;;){
        int N[50];
        
        scanf("%d %d", &n, &r);
        
        if( n == 0 && r == 0){
            break;
        }
        
        for( i = 0; i < n; i++){
            N[i] = n-i;
        }
        
        //cut
        for( ; r > 0; r--){
            scanf("%d %d", &p, &c);
            int copy[50];
            for( i = 0; i < p-1+c; i++){
                copy[i] = N[i];
            }
            for( i = 0; i < p-1+c; i++){
                if( i < c){
                    N[i] = copy[p-1+i];
                }
                
                else{
                    N[i] = copy[i-c];
                }
            }
        }
        
        printf("%d\n", N[0]);
    }
    
    return 0;
}

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

ll GCD(ll a, ll b) {
  return b ? GCD(b, a%b) : a;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  
  vector<ll> left(N+1, 0);
  vector<ll> right(N+1, 0);
  rep(i, N) left[i+1] = GCD(left[i], A[i]);
  for (ll i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], A[i]);

  ll ans = 0;
  rep(i, N) {
    ll l = left[i];
    ll r = right[i+1];
    ans = max(ans, GCD(l, r));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5644
#include <iostream>

using namespace std;

void print_data(int data[], int N) {
    cout << data[0];
    for (int i = 1; i < N; i++) cout << " " << data[i];
    cout << endl;
}

int selection_sort(int data[], int N) {
    int swap_count = 0;

    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (data[j] < data[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(data[i], data[minj]);
            swap_count++;
        }
    }

    return swap_count;
}

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

    int data[N];
    for (int i = 0; i < N; i++) cin >> data[i];
    int swap_count = selection_sort(data, N);
    print_data(data, N);
    cout << swap_count << endl;
    
    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <set>
#define int long long
using namespace std;
set<int>s;
signed main() {
	int q; cin >> q;
	for (int t = 0; t < q; t++) {
		int a, b; cin >> a >> b;
		if (!a) {
			s.insert(b);
			cout << s.size() << endl;
		}
		else {
			cout << s.count(b) << endl;
		}
	}
}


Measured memory_bytes: 12380
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<int, ll> pr;
vector<int>t[100004];

int f(int x){
    if(x%2==0){
        return x/2;
    }
    else{
        return x*3+1;
    }
}
bool x[1000002];
int main(){
    int s;
    cin>>s;
    x[s]=true;
    for(int i=0;i<1000001;i++){
        s=f(s);
        if(x[s]){
            cout<<i+2<<endl;break;
        }x[s]=true;
    }
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

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

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long x1 = a*c;
		long x2 = a*d;
		long x3 = b*c;
		long x4 = b*d;

		long ans = Math.max(x1,x2);
		ans=Math.max(ans, x3);
		ans=Math.max(ans, x4);
			System.out.println(ans);
		
	}
}

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

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

  if(a>b){
    cout << "a > b" << endl;
  }else if(a<b){
    cout << "a < b" << endl;
  }else if(a==b){
    cout << "a == b" << endl;
  }
  
  return 0;

}

Measured memory_bytes: 3088
class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod


N, K = map(int, input().split())
mod = 10**9+7
c = Combi(4*10**5+100, mod)
if N <= K:
    print(c.com(2*N-1, N-1))
else:
    ans = c.com(2*N-1, N-1)
    for i in range(K+1, N):
        ans -= c.com(N-1, N-i-1)*c.com(N, i)
    print(ans % mod)

Measured memory_bytes: 124176
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

struct query {
	int id; ll a, b;
};

struct BIT {
private:
	vector<ll> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, ll w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	ll sum(int a) {
		ll ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	ll sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

void solve() {
	int q; cin >> q;
	multiset<ll> st;
	vector<query> v(q);

	vector<ll> x;
	ll alsum = 0;
	rep(i, q) {
		cin >> v[i].id;
		if (v[i].id == 1) {
			cin >> v[i].a >> v[i].b;
			x.push_back(v[i].a);
		}
	}
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	map<ll, int> mp;
	rep(i, x.size())mp[x[i]] = i;
	//cout << x.size() << endl;
	BIT b(x.size()),num(x.size());
	int len = 0;
	rep(i, q) {
		if (v[i].id == 2) {
			int le = 0, ri = x.size();
			while (ri - le > 1) {
				int mid = (le + ri) / 2;
				if (num.sum(mid) <= (len-1) / 2)le = mid;
				else ri = mid;
			}
			ll lesum = b.sum(le); ll lenum = num.sum(le);
			ll risum = b.sum(le, x.size()); ll rinum = num.sum(le,x.size());
			ll sum = (lenum - rinum)*x[le] + risum - lesum + alsum;
			cout << x[le] << " " << sum << endl;
		}
		else {
			len++;
			num.add(mp[v[i].a], 1);
			b.add(mp[v[i].a], v[i].a);
			alsum += v[i].b;
		}
	}

}

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


Measured memory_bytes: 15860
from collections import deque

N = int(input())
v = list(map(int, input().split()))
v.sort()

V = deque(v)
while len(V) > 1:
    a = V.popleft()
    b = V.popleft()
    V.appendleft((a + b) / 2)

print(V.pop())


Measured memory_bytes: 38512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
int n;
char s;
ll c[300];
ll f[300][300];
ll sf[300][300];
ll ans=0;
ll M=1000000007;


int main()
{
    cin>>n;
    for (int i=0; i<n; ++i)
    {
        scanf("%c",&s);
        while (s=='\n')
            scanf("%c",&s);
        c[s]++;
    }
    for (int i=1; i<=26; ++i)
        for (int j='a'; j<='z'; ++j)
        {
            if (i==1)
            {
                sf[i][j]=(sf[i][j-1]+c[j])%M;
            }
            else 
            {
                sf[i][j]=(sf[i][j-1]+sf[i-1][j-1]*c[j])%M;
            }
            if (j=='z')
                ans+=sf[i][j];
            ans%=M;
        }
    cout<<ans<<endl;
    return 0;
}



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

typedef long long ll;
static const int N = 1e5 + 10;
static const int inf = 0x3f3f3f3f;
ll n, k, a[N];

int main ()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    ll ans = inf;
    for (ll i = k; i <= n; ++i)
    {
        ll l = i - k + 1;
        ll r = i;
        if (a[l] * a[r] < 0)
        ans = min(ans, min(abs(a[l]), abs(a[r])) * 2 + max(abs(a[l]), abs(a[r])));
        else
        ans = min (ans, max(abs(a[l]), abs(a[r])));
//        cout << ans << endl;
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

bool from1[2505];
bool fromN[2505];
bool ok[2505];
vector<vl> G(2505);
vector<vl> rG(2505);



int main(){
    ll r; cin >> r;
    if(r < 1200) puts("ABC");
    else if(r < 2800) puts("ARC");
    else puts("AGC");
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  string s;
  cin >> s;
  if(s[0]==s[1]&&s[1]==s[2]&&s[0]==s[2])cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())

r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == "R":
        r += 1
        s[i] = 1
    elif s[i] == "G":
        g += 1
        s[i] = 2
    else:
        b += 1
        s[i] = 4

cnt = r*g*b

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k < n:
            if s[i] + s[j] + s[k] == 7:
                cnt -= 1

print(cnt)


Measured memory_bytes: 68052
//package compilers;

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		int []arr=new int[n];
		int []dp= new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,Integer.MAX_VALUE);
		dp[0]=0;
		
		for(int i=1;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0) {
					dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(arr[i]-arr[i-j]));
				}
			}
		}
		System.out.println(dp[n-1]);
	}

}


Measured memory_bytes: 56164
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String S = sc.next();
		String T = sc.next();

		int A = sc.nextInt();
		int B = sc.nextInt();

		String U = sc.next();

		sc.close();

		if (U.equals(S)) {
			A--;
		} else {
			B--;
		}

		out.println(A + " " + B);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


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

using namespace std;
int f[1050];
typedef unsigned long long ll;
int main()
{
    ll n,k;
    cin >> n >> k;
    ll t=n%k;
    if(t>k-t)
        t=k-t;
    if(t>k-n)
        t=k-n;
    cout << t;
    return 0;
}


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

using namespace std;

int main()
{
   int n;
   cin>>n;
   int arr[n];
   for(int i=0;i<n;i++)
   {
      int y;
      cin>>y;
      arr[i]=y;
   }
  
   long long int sum=0;
   for(int i=1;i<n;i++)
   {
      if(arr[i]<arr[i-1])
      {
          sum+=(arr[i-1]-arr[i]);
          arr[i]=arr[i-1];
      }
   }
 cout<<sum;
}


Measured memory_bytes: 4384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    string s;
    cin >> s;
    int K;
    cin >> K;
    set<string> st;
    REP(i, 0, s.size()) {
        REP(j, 0, K) {
            st.insert(s.substr(i, j + 1));
        }
    }
    auto it = st.begin();
    REP(i, 0, K - 1) {
        it++;
    }
    cout << *it << endl;
    return 0;
}

Measured memory_bytes: 1664
while true
	tensu = gets.split.map(&:to_i)
	m = tensu[0]
	f = tensu[1]
	r = tensu[2]

	if m == -1 && f == -1 && r == -1
		break
	elsif m == -1 || f == -1
		puts "F"
	elsif m + f >= 80
		puts "A"
	elsif m + f >= 65 && m + f < 80
		puts "B"
	elsif m + f >= 50 && m + f < 65 || r >= 50
		puts "C"
	elsif m + f >= 30 && m + f < 50
		puts "D"
	else
		puts "F"
	end
end

Measured memory_bytes: 6104
#include<cstdio>
#include<algorithm>
int read(){
	int c=getchar(),ret=0,f=1;
	while (c<'0'||c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9')ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret*f;
}
bool cmp(int a,int b){return a>b;}
int min(int a,int b){return a<b?a:b;}
int a[100050],b[100050],ta,tb;
int main(){
	int n=read(),k=read();
	for (int i=1;i<=n;i++){
		int p=read();
		if (!p){
			k--;
			if (k<=0){
				printf("0\n");
				return 0;
			}
		}
		else if (p<0)a[++ta]=p;
		else b[++tb]=p;
	}
	std::sort(a+1,a+ta+1,cmp);
	int ans=2e9;
	for (int i=1;i<=ta&&i<=k;i++)if (k-i<=tb)ans=min(ans,((-a[i])<<1)+b[k-i]);
	for (int i=1;i<=tb&&i<=k;i++)if (k-i<=ta)ans=min(ans,(b[i]<<1)-a[k-i]);
	if (ta>=k)ans=min(ans,-a[k]);
	if (tb>=k)ans=min(ans,b[k]);
	printf("%d\n",ans);
}

Measured memory_bytes: 512
n=int(input())

A=[int(i)-1 for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]

manzoku=sum(B)

for i in range(1,n):
    if A[i]==A[i-1]+1:
        manzoku+=C[A[i-1]]

print(manzoku)

Measured memory_bytes: 38384
#!/usr/bin/perl

$line = 0;
while(<>) {
    chomp;
    if ($line == 0) {
        $n = $_;
    } else {
        $k = $_;
    }
    $line++;
}

$ans = 1;
foreach (1 .. $n) {
    if ($ans < $k) {
        $ans *= 2;
    } else {
        $ans += $k;
    }
}
print "$ans\n";


Measured memory_bytes: 640
/// b.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,a,b;
    fi>>n>>a>>b;
    a -= b;
    static int s[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    auto f = [&](ll k)
    {
        ll ans = 0;
        for (int i = 1;i <= n;++i)
            ans += (max(0ll,s[i] - k * b) + a - 1) / a;
        return (ans <= k);
    };
    ll ans = 1ll << 31;
    for (ll t = 1ll << 31;t;t /= 2)
        if (ans >= t && f(ans - t))
            ans -= t;
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 640
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,K = map(int,S().split())
A = LI()
mod = 10**9+7

ans = 1

if N == K:
    for i in range(N):
        ans *= A[i]
        ans %= mod
    print(ans)
    exit()

B = []  # 非負の要素
C = []  # 負の要素
for i in range(N):
    if A[i] >= 0:
        B.append(A[i])
    else:
        C.append(A[i])
b = len(B)  # 非負の要素の個数
c = len(C)  # 負の要素の個数

if c == N and K % 2 == 1:
    A.sort(reverse=True)
    for i in range(K):
        ans *= A[i]
        ans %= mod
    print(ans)
    exit()

# 以下、K個の積を非負にできる場合のみ残る

B.sort(reverse=True)
C.sort()
d = 0  # Bから選んだ個数
e = 0  # Cから選んだ個数

# ansを非負に維持しながら、Bの要素を1個ずつ、もしくはCの要素を2個ずつ掛け合わせていく

while d + e < K:
    if d + e == K-1:
        ans *= B[d]
        ans %= mod
        d += 1
    else:
        if e >= c-1:
            ans *= B[d]
            ans %= mod
            d += 1
        elif d >= b-1:
            ans *= C[e]*C[e+1]
            ans %= mod
            e += 2
        else:
            if B[d]*B[d+1] < C[e]*C[e+1]:
                ans *= C[e]*C[e+1]
                ans %= mod
                e += 2
            else:
                ans *= B[d]
                ans %= mod
                d += 1

print(ans)

Measured memory_bytes: 107132
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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 pair<ll,ll> P;

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    string s;cin>>s;
    vector<char> s_,s__;
    rep(i,s.size()){
        if(s[i] == 'x')continue;
        s_.push_back(s[i]);
        s__.push_back(s[i]);
    }
    reverse(s__.begin(),s__.end());
    for(int i = 0;i < s_.size();i++){
        if(s_[i]!=s__[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    int i = 0,j = 0;
    vector<int> lst(s_.size()+1,0);

    while(j < s_.size()){
        if(s[i] == s_[j]){
            i++;j++;
        }else{
            lst[j]++;
            i++;
        }
    }
    if(i < s.size())lst[s_.size()]=s.size()-i;
    auto it_b = lst.begin();
    auto it_e = lst.end()-1;
    ll ans = 0;
    while(it_b < it_e){
        ans += abs(*it_b - *it_e);
        it_b++;it_e--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }
    return ret;
}

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

    int n, K;
    cin >> n >> K;

    int sum = 0;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        sum += A[i];
    }

    vector<int> div = divisor(sum);
    sort(div.begin(), div.end(), greater<int>());

    for (int d : div) {
        vector<int> vec(n);
        for (int i = 0; i < n; i++) vec[i] = A[i] % d;
        sort(vec.begin(), vec.end());

        vector<int> l(n);
        for (int i = 0; i < n; i++) {
            l[i] = vec[i];
            if (i) l[i] += l[i - 1];
        }

        vector<int> r(n);
        for (int i = n - 1; i >= 0; i--) {
            r[i] = d - vec[i];
            if (i < n - 1) r[i] += r[i + 1];
        }

        bool f = false;
        if (l[n-1] == 0) f = true;
        for (int i = 0; i < n - 1; i++) {
            if (l[i] == r[i + 1] && l[i] <= K) {
                f = true;
                break;
            }
        }

        if (f) {
            cout << d << "\n";
            break;
        }
    }

    return 0;
}

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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr <<">>>>>>"<< #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif


int main()
{
	
	long long a,b,x;
	cin>>a>>b>>x;
	cout<<b/x-a/x+((a%x)==0)<<endl;
	
	
}



Measured memory_bytes: 3608
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
#include <set>
#include <string>
#include <iterator>
#include <queue>
#include <cmath>
#include <cassert>

typedef long long ll;
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)

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

    ll ans = 0;
    for (ll a = 0; a <= 3000; a++) {
        for (ll b = 0; b <= 3000; b++) {
            ll leftc = N - a * R - b * G;
            if (leftc < 0) continue;
            if (leftc % B == 0) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;

  for (int i = 1; i <= 1000; i++) {

    if (((int)(i*0.08))==A && ((int)(i*0.1))==B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=-float('inf')
for i in range(n):
  T=1
  index=p[i]-1
  T_score=c[index]
  flag=True
  while flag:
    T+=1
    index=p[index]-1
    T_score+=c[index]
    if index==i:
      flag=False
  #場合分け開始
  if T>=k:
    score_list=[c[p[i]-1]]+[0]*(k-1)
    index=p[i]-1
    for s in range(1,k):
      index=p[index]-1
      score_list[s]=score_list[s-1]+c[index]
    score=max(score_list)
  else:
    if T_score<=0:
      score_list=[c[p[i]-1]]+[0]*(T-1)
      index=p[i]-1
      for s in range(1,T):       
        index=p[index]-1
        score_list[s]=score_list[s-1]+c[index]        
      score=max(score_list)
    else:
      m1=k//T
      m2=k%T
      score_list=[c[p[i]-1]]+[0]*(T+m2-1)
      index=p[i]-1
      for s in range(1,T+m2):
        index=p[index]-1
        score_list[s]=score_list[s-1]+c[index]
      score=max(score_list)+T_score*(m1-1)
  ans=max(ans,score)
print(ans)

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  long x, k, d;
  cin >> x >> k >> d;
  long now = x;
  long count = 0;
  count = (abs(now) + d - 1) / d;
  if (count > k) {
    cout << abs(now) - d * k;
    return 0;
  }

  if ((k - count) % 2 == 0) {
    cout << abs(abs(now) - d * count) << endl;
  } else {
    cout << abs(abs(abs(now) - d * count) - d) << endl;
  }
}


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

const int nex = 1e5 + 5;

using namespace std;

vector<int>edg[nex];
int dist[nex];
int in_degree[nex];
bool visted[nex];

void dfs(int a){
    visted[a] =1;
    for(int b: edg[a]){
        dist[b] = max(dist[b], dist[a]+1);
        in_degree[b]--;
        if(in_degree[b]==0){dfs(b);}
    }
}

int main(){
    int n, m, a, b;
    scanf("%d%d", &n, &m);
    while(m--){
        scanf("%d%d", &a, &b);
        edg[a].push_back(b);
        in_degree[b]++;
    }
    for(int i=1; i<=n; i++){
        if(!visted[i] && in_degree[i]==0){dfs(i);}
    }
    auto ans = max_element(begin(dist), end(dist));
    
    printf("%d", *ans);
}

Measured memory_bytes: 9728