akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<deque>
#include<functional>
#include<ctime>
#include<cassert>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;
typedef vector<int> vi;

template<class T> bool uin(T &a, T b){ return (a > b ? a = b, true : false); }
template<class T> bool uax(T &a, T b){ return (a < b ? a = b, true : false); }

/////////////////////////////////

int const MOD = 1e9 + 7;
int const N = 5e3 + 41;

int f[N], invf[N], invn[N];
int n;
vi e[N];
int d[N][N];

void add(int &a, int b){
	a += b;
	while(a >= MOD) a -= MOD;
	while(a < 0) a += MOD;
}

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

int q[N];
vi c;

void dfs(int x, int p = -1){
	int mq = 0;
	q[x] = 1;
	for(int y : e[x]){
		if(y == p) continue;
		dfs(y, x);
		q[x] += q[y];
		uax(mq, q[y]);
	}
	uax(mq, n-q[x]);
	if(mq * 2 <= n) c.pb(x);
}

int getc(int n, int k){
	int res = f[n];
	res = mul(res, invf[k]);
	res = mul(res, invf[n-k]);
	return res;
}

int main(){
#ifdef LOCAL_DEFINE
	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, n-1){
		int x, y;
		scanf("%d %d",&x,&y);
		--x;--y;
		e[x].pb(y);
		e[y].pb(x);
	}	
	f[0] = 1;
	fi(1, N) f[i] = mul(f[i-1], i);
	fi(0, 2) invn[i] = invf[i] = 1;
	fi(2, N){
		invn[i] = mul(MOD - MOD/i, invn[MOD%i]);
		invf[i] = mul(invf[i-1], invn[i]);
//		if(i < 10)	cerr << i << " " << invn[i] << endl;
	}
	dfs(0);
	if(sz(c) == 2){
		printf("%d\n",mul(f[n/2],f[n/2]));
		return 0;
	}
//	for(int x : c) printf("c = %d\n",x);
	int s = 0;
	vi a;
	for(int y : e[c[0]]){
		if(q[y] > q[c[0]]) continue;
		s += q[y];
		a.pb(q[y]);
	}
	if(n-1-s > 0) a.pb(n-1-s);
	d[0][0] = 1;
	fi(0, sz(a)) fj(0, n) fo(0, a[i]+1){
		if(j + o >= N) continue;
		int v0 = d[i][j];
		int v1 = getc(a[i], o);
	//	cerr << "v1 = " << v1 << endl;
		v1 = mul(v1, v1);
		v1 = mul(v1, f[o]);
		v1 = mul(v1, v0);
		add(d[i+1][j+o], v1);
	}			    	
//	fi(0, n+1) cerr << "d[i] = " << i << " " << d[sz(a)][i] << endl;
//	for(int x : a) cerr << x << endl;
	int ans = 0;
	fi(0, n){		
		int v0 = d[sz(a)][i];
	//	cerr << v0 << endl;
		int v1 = f[n-i];
		int v = mul(v0, v1);
		if(i&1) v = -v;
		add(ans, v);
	}
//	ans = mul(ans, n);
	printf("%d\n",ans);
	
#ifdef LOCAL_DEFINE
	fprintf(stderr, "ELAPSED TIME: %.3lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}


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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a==b&&a!=c||a==c&&a!=b||b==c&&b!=a)
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
        var n int
        var a, b string
        sc := bufio.NewScanner(os.Stdin)
        fmt.Scanf("%d", &n)
        for i := 0; i < n; i++ {
                sc.Scan()
                a = sc.Text()
                sc.Scan()
                b = sc.Text()

                if len(a) > len(b) {
                        s := add(a, b)
                        if s[len(a)] > 0 {
                                if len(a) >= 80 {
                                        fmt.Printf("overflow")
                                } else {
                                        for i := 0; i <= len(a);i++ {
                                                fmt.Printf("%d", s[len(a)-i])
                                        }
                                }
                                fmt.Printf("\n")
                        } else {
                                if len(a)-1 >= 80 {
                                        fmt.Printf("overflow")
                                } else {
                                        for i := 0; i < len(a);i++ {
                                                fmt.Printf("%d", s[len(a)-i-1])
                                        }
                                }
                                fmt.Printf("\n")
                        }
                } else {
                        s := add(b, a)
                        if s[len(b)] > 0 {
                                if len(b) >= 80 {
                                        fmt.Printf("overflow")
                                } else {
                                        for i := 0; i <= len(b);i++ {
                                                fmt.Printf("%d", s[len(b)-i])
                                        }
                                }
                                fmt.Printf("\n")
                        } else {
                                if len(b)-1 >= 80 {
                                        fmt.Printf("overflow")
                                } else {
                                        for i := 0; i < len(b);i++ {
                                                fmt.Printf("%d", s[len(b)-i-1])
                                        }
                                }
                                fmt.Printf("\n")
                        }
                }
        }
}

// expects ln > lm
func add(n string, m string) (s [100]int) {
        ln := len(n)
        lm := len(m)
        var sum [100]int

        for i := 0; i < ln; i++ {
                var s, t int
                s = int(n[ln-1-i]) - int('0')

                if lm - 1 - i >= 0 {
                        t = int(m[lm-1-i]) - int('0')
                } else {
                        t = 0
                }

                sum[i+1] = (s + t + sum[i]) / 10
                sum[i] = (s + t + sum[i]) % 10
        }

        return sum
}



Measured memory_bytes: 1152
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def S(): return input().rstrip()
def LIR(n): return [S().split() for i in range(n)]

def main():
    s = S(); Q = I()
    mode = 2
    d = deque(s)

    for i in range(Q):
        query = S()
        if query[0] == "1": mode = 3 - mode
        else:
            t, f, c = map(str, query.split())
            if (int(f) + mode)% 2  == 0: d.append(c)
            else: d.appendleft(c)
    if mode == 2: print(''.join(d))
    else: print(''.join(list(d)[::-1]))

if __name__ == '__main__':
    main()

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

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
#define PI 3.14159265
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n; cin >> n;
    vector<int> v(n);
    vector<int> cnt(30);
    for (int i = 0; i < n; ++i) {
        int num; cin >> num;
        v[i] = num;
        for (int j = 0; j < 30; ++j) {
            cnt[j] += (num & (1 << j)) == 0 ? 0 : 1;
        }
    }
    
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 30; ++j) {
            if (cnt[j] % 2 == 1) {
                v[i] = v[i] ^ (1 << j);
            }
        }
    }
    
    for (auto el : v) {
        cout << el << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <vector>

using namespace std;

int main(){
    
    long long n, som = 1;  
    bool ze = false, o = false;  

    cin >> n;

    vector<long long> v (n);   

    for(long long i = 0; i < n; i++){
        cin >> v[i];
        //cout << v[i] << endl;
        if(v[i] == 0)
            ze = true;
    }

    if(!ze){
        for(long long i = 0; i < n; i++){
			long long oldsom = som;
            som = v[i] * som;
			if(som > 1000000000000000000 || som < oldsom ){
				o = true;
				break;
			}
			if(som/v[i] != oldsom){
				o = true;
				break;
			}
        }
    }

    if(ze){
        cout << "0" << endl;
    }else if(o){
        cout << "-1" << endl;
    }else{
        cout << som << endl;
    }

    return 0;
}



Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>

using ll = long long;

int main()
{
    int N, Q;
    std::cin >> N >> Q;
    std::string S;
    std::cin >> S;
    std::vector<int> l(Q), r(Q);

    for (int i = 0; i < Q; i++)
    {
        std::cin >> l[i] >> r[i];
    }

    std::vector<int> sums(N + 1);
    sums[0] = 0;
    for (int i = 1; i < N + 1; i++)
    {
        if (S[i - 1] == 'A' && S[i] == 'C')
        {
            sums[i] = sums[i - 1] + 1;
        }
        else
        {
            sums[i] = sums[i - 1];
        }
    }

    for (int i = 0; i < Q; i++)
    {
        int right = r[i] - 1;
        int left = l[i] - 1;
        std::cout << sums[right] - sums[left] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	int r;
	cin >> r;
	
	
	cout << setprecision(6) << fixed << 2 * acos(-1) * r << endl;


	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n, m;
    cin >> n >> m;
    if(n < m) rep(i, m) cout << n;
    else rep(i, n) cout << m;
    cout << endl;
}

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

#最大の区間を求める

ma = k - (a[-1] - a[0])

for i in range(n-1):
	tmp = a[i+1] - a[i]
	if tmp > ma:
		ma = tmp

print(k-ma)

Measured memory_bytes: 78540
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
int cnt;
string str;

int main(){
    cin >> n;
    rep(i,n){
        cin >> str;
        if(str == "A") cnt++;
        else cnt--;
        if(cnt < 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    if(cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
# X Cubic
#	Write a program which calculates the cube of a given integer x.
#
# Input
#	An integer x is given in a line.
#
# Output
#	Print the cube of x in a line.
#
# Constraints
#	1 ≤ x ≤ 100
# Sample Input 1
#	2
# Sample Output 1
#	8
# Sample Input 2
#	3
# Sample Output 2
#	27

x = int(input())
print(x * x * x)



Measured memory_bytes: 5580
import Data.Array

main :: IO ()
main = do
  n <- readLn
  hs <- fmap (map read . words) getLine :: IO [Int]
  print $ solve n hs

solve :: Int -> [Int] -> Int
solve n hs = dp ! n
  where
    harr = listArray (1, n) hs
    dp = listArray (1, n) $ map f [1..n]
    f :: Int -> Int
    f 1 = 0
    f 2 = cost 1 2
    f i = min (dp!(i-1) + cost i (i-1)) (dp!(i-2) + cost i (i-2))
    cost i j = abs (harr!i - harr!j)

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

int main(){
	int n;
	int ice[10000];
	int k[16];

	while(cin >>n,n){

		for(int i=0;i<16;i++){
			k[i]=0;
		}

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


		for(int i=0;i<n;i++){
			switch(ice[i]){
				case 0: k[0]++; break;
				case 1: k[1]++; break;
				case 2: k[2]++; break;
				case 3: k[3]++; break;
				case 4: k[4]++; break;
				case 5: k[5]++; break;
				case 6: k[6]++; break;
				case 7: k[7]++; break;
				case 8: k[8]++; break;
				case 9: k[9]++; break;
			}
		}
/*
		cout <<endl;
		for(int i=0;i<10;i++)
			cout << k[i] <<endl;
*/		

		for(int i=0;i<10;i++){
			if(k[i] > 0){
				for(int j=0;j<k[i];j++){
					cout <<"*";
				}
				cout << endl;
			}else {
				cout <<"-" <<endl;
			}
		}

	}


	return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll x; cin >> x;
    ll now = 100;
    int ans = 0;
    while (now < x) {
        now = (ll)(now * 1.01);
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
n,m,k=gets.split.map(&:to_i)
mod=998244353
f=[1]
n.times do |i|
  f << f[i]*(i+1)%mod
end
def mi(a,m)
  b=m
  u=1
  v=0
  while b>0
    t=a/b
    a-=t*b
    u-=t*v
    a,b=b,a
    u,v=v,u
  end
  u%=m
  if u<0
    u+=m
  end
  return u
end
mm=1
(n-1-k).times do |i|
  mm=mm*(m-1)%mod
end
ans=0
k.downto(0) do |l|
  ans+=mm*mi(f[l],mod)*mi(f[n-1-l],mod)%mod
  mm=mm*(m-1)%mod
end
puts ans*m*f[n-1]%mod


Measured memory_bytes: 16140
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 2e9
#define ll long long
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) v.begin(), v.end()

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int h1; cin >> h1;
    int r = 1;
    REP(i, n-1) {
        int h; cin >> h;
        if (h >= h1) {
            r++;
            h1 = h;
        }
    }
    cout << r << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.next();
		String t = sc.next();
		char[] sa = s.toCharArray();
		char[] ta = t.toCharArray();
		int count = 0;
		for (int i = 0; i < sa.length; i++) {
			if (sa[i] != ta[i]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 41928
l[10];main(v,V,i,s){
	for(;~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v,&V);){
		for(i=s=0;i<10;i++)s+=l[i];
		double t=s*1.0/(v+V),p=v*t-0.1;
		for(i=s=0;i<10;i++){
			s+=l[i];
			if(s>p)break;
		}
		printf("%d\n",i+1);
	}
	exit(0);
}

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

int main() {

  int a,b,c,n;
  int count = 0;
  cin >> n;
 
vector<int> A(n);
for (int i = 0; i < n; i++) {
  		cin >> A.at(i);
  		--A[i];
	}
  
vector<int> B(n);
for (int i = 0; i < n; i++) {
  		cin >> B.at(i);
	}  

 //ここから下に原因がある。 
vector<int> C(n);
for (int i = 0; i < n-1; i++) {
		cin >> C.at(i);
	}
for (int i=0; i<n; i++){
	count += B.at(A.at(i));
  	if(i>0 && A.at(i) == A.at(i-1) + 1) count += C.at(A.at(i-1)); //ここはOK
}
  cout << count <<endl;  
} 

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete



main = do
    n <- getInt
    unless (n==0) $ map fst . sortBy (comparing snd) . map (fmap (fnTuple (negate . length . filter (==0), length . filter (==1)) . map readInt) . (\(h:t) -> (h,t)) . words) <$> replicateM n getLine >>= mapM_ putStrLn >> main



Measured memory_bytes: 4080
s = input()
length = len(s)
black_s = ["0" if x %2 == 0 else "1" for x in range(length) ]
white_s = ["0" if x %2 == 1 else "1"for x in range(length)]

black = 0
white = 0
for index, x in enumerate(s):
    if x != black_s[index]:
        black += 1

    if x!= white_s[index]:
        white += 1
else:
    print(min(black, white))


Measured memory_bytes: 4852
buf = input().split(" ")
N=int(buf[0])
K=int(buf[1])
 
H = list(map(int, input().split())) 
 
H=sorted(H)

for i in range(K):
  if len(H) == 0 :
    break
  H.pop()

if len(H) != 0:
  print(sum(H))
else:
  print(0)
  

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

using namespace std;

long long n,i,j,ans,sum,num[100005];
string s[100005],now;

int main()
{
	scanf("%lld\n",&n);
	
	for(i=0;i<n;i++)
	{
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}
	
	sort(s,s+n);
	
	for(i=0;i<n;i++)
	{
		if(now!=s[i])
		{
			now=s[i];
			num[sum]=1;
			sum++;
		}
		else num[sum-1]++;
	}
	
	for(i=0;i<sum;i++)
		ans+=(num[i]*(num[i]-1))/2;
	
	printf("%lld",ans);
	return 0;
}

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

public class Main {
	
	static int c,d,n,m;
	static int adj[][] = {{-1,0},{1,0},{0,-1},{0,1}};
	static int maj[][] = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1},{-2,-2},{-2,-1},{-2,0},{-2,1},{-2,2},{-1,-2},{0,-2},{1,-2},{2,-2},{2,-1},{2,0},{2,1},{2,2},{-1,2},{0,2},{1,2}};                            ;
	static int board[][];
	
	static boolean legal(int x, int y) {
		if(x<0||y<0||x>=n||y>=m||board[x][y]==1) return false;
		else return true;
	}
	
	public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        n = in.nextInt();m = in.nextInt();
        int a = in.nextInt()-1;int b = in.nextInt()-1;
        int c = in.nextInt()-1;int d = in.nextInt()-1;
        board = new int[n][m];
        for(int i=0;i<n;i++) {
        	char ch[] = in.next().toCharArray();
        	for(int j=0;j<m;j++) {
        		if(ch[j]=='#') board[i][j] = 1;
        	}
        }
        int dis[][] = new int[n][m];
        for(int x=0;x<n;x++) Arrays.fill(dis[x], 1_000_000_000);
        ArrayDeque<Integer> qx = new ArrayDeque<>();
        ArrayDeque<Integer> qy = new ArrayDeque<>();
        qx.add(a);qy.add(b);
        dis[a][b] = 0;
        while(!qx.isEmpty()) {
        	int curX = qx.removeFirst(), curY = qy.removeFirst();
        	for(int x[] : adj) {
        		int nx = curX+x[0], ny = curY+x[1];
        		if(legal(nx,ny)) {
        			if(dis[nx][ny]>dis[curX][curY]) {
        				dis[nx][ny] = dis[curX][curY];
        				qx.addFirst(nx);
        				qy.addFirst(ny);
        			}
        		}
        	}
        	for(int x[] : maj) {
        		int nx = curX+x[0], ny = curY+x[1];
        		if(legal(nx,ny)) {
        			if(dis[nx][ny]>dis[curX][curY]+1) {
        				dis[nx][ny] = dis[curX][curY]+1;
        				qx.addLast(nx);
        				qy.addLast(ny);
        			}
        		}
        	}
        }
        out.println((dis[c][d]==1e9)?"-1":dis[c][d]);
        out.flush();
	}
	
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int a[] = new int[n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		long[] readArray(int n,long x) {
			long a[] = new long[n];
			for(int i=0;i<n;i++) a[i] = nextLong();
			return a;
		}
		
	}
}











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

// --------------------------------------------------------------------------------
#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define frepi(a,b) for(int i=a;i<=b;++i)
// --------------------------------------------------------------------------------

void solve_main()
{
    int a,b,c;cin>>a>>b>>c;
    int k;cin>>k;
    int count = 0;
    while(b<=a)b = b*2,count++;
    while(c<=b)c = c*2,count++;
    cout<<((count<=k)?"Yes\n":"No");
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("/home/suryakant/input.txt","r",stdin);
		freopen("/home/suryakant/output.txt","w",stdout);
	#endif
	
    int t=1;
    // cin>>t;
    while(t--)
    {
    	solve_main();
    }    
}

Measured memory_bytes: 3644
n,k = gets.strip.split.map(&:to_i)
array = gets.strip.split.map(&:to_i).sort
answer = 0

if (num = array.uniq.count) > k
  counts = array.group_by(&:itself).map { |k, v| [k, v.count] }.sort_by(&:last)
  (num - k).times do |i|
    answer += counts[i][1]
  end
end

puts answer



Measured memory_bytes: 59592
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 1000000007;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x, y;
  cin >> x >> y;
  int base = x * 2;
  y -= base;
  if (y < 0)
  {
    cout << "No";
  }
  else
  {
    if (y <= 2 * x && y % 2 == 0)
      cout << "Yes";
    else
      cout << "No";
  }

}

Measured memory_bytes: 3656
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ss=[""]*k
ans=0
for i in range(n):ss[i%k]+=t[i]
for t in ss:
  m=len(t)
  dp=[[0,0,0]for _ in range(m)]
  #rsp
  if t[0]=="r":dp[0]=[0,0,p]
  elif t[0]=="s":dp[0]=[r,0,0]
  else:dp[0]=[0,s,0]
  for i in range(1,m):
    dp[i]=[max(dp[i-1][1],dp[i-1][2]),max(dp[i-1][0],dp[i-1][2]),max(dp[i-1][0],dp[i-1][1])]
    if t[i]=="r":
      dp[i][2]+=p
    if t[i]=="s":dp[i][0]+=r
    if t[i]=="p":dp[i][1]+=s
  ans+=max(dp[-1])
print(ans)

Measured memory_bytes: 16372
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
s = []
p = []
for i in range(n):
    a, b = na()
    s.append((a, b))
for i in range(m):
    c, d = na()
    p.append((c, d))
for i in range(n):
    ans = float("inf")
    pt = 0
    for j in range(m):
        dif = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])
        if dif < ans:
            ans = dif
            pt = j + 1
    print(pt)


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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=0;i<=(n);i++)

int main(){
	int t;
	int x[4];
	in(n);

	x[0] = n % 10;
	n /= 10;
	x[1] = n % 10;
	n /= 10;
	x[2] = n % 10;
	n /= 10;
	x[3] = n % 10;
	n /= 10;

	if(((x[0] == x[1]) && (x[1] == x[2])) || ((x[1] == x[2]) && (x[2] == x[3])))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

#define ll long long 
#define pb push_back
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()

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

	ll n, x, t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t << "\n";

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    int n;
    std::cin >> n;
    VEC(int,d,n);
    int m;
    std::cin >> m;
    VEC(int,t,m);
    std::map<int,int> mm;
    rep(i,n){
        mm[d[i]]++;
    }
    bool b=1;
    rep(i,m){
        if(mm[t[i]]>0){
            mm[t[i]]--;
        }
        else{
            b=0;
        }
    }
    if(b)std::cout << YES << std::endl;
    else std::cout << NO << std::endl;
}

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

int main(){
  int a,b,log=0;
  cin>>a>>b;
  int num[999];
  num[0] = 1;
  for(int i=1;i<999;i++){
    num[i] =  num[i-1] +i+1;
    if(num[i]<a) log = i;
  }
  int ans=0;
  while(num[log]<=a+ans){
    for(int i=log;num[i]<=a+ans;i++){
      if(num[i]==a+ans && num[i+1]==ans+b){
        cout<<ans<<endl;
        return 0;
      }
    }
    ans++;
  }cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if h == w == 0:
        break
    else:
        for i in range(h):
            for j in range(w):
                if i%2==1 and j%2==1:
                    print("#",end="")
                elif i%2==1 and j%2==0:
                    print(".",end="")
                elif i%2==0 and j%2==1:
                    print(".",end="")
                else:
                    print("#",end="")
            print()
    print()               


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

const int NODE_MAX = 200000;
vector<int> tree[NODE_MAX+1];

void dfs(int my, int par, vector<long long> &ct) {
  ct[my] += ct[par];
  for ( int i = 0; i < tree[my].size(); i++ ) {
    if ( tree[my][i] == par ) { continue; }
    dfs(tree[my][i], my, ct);
  }
}

int main() {
  int n, q;
  cin >> n >> q;

  tree[0].push_back(1);
  for ( int i = 0; i < n-1; i++ ) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  
  vector<long long> ct(n+1, 0);
  while ( q-- > 0 ) {
    int p, x;
    cin >> p >> x;
    ct[p] += x;
  }

  dfs(1, 0, ct);

  for ( int i = 1; i <= n; i++ ) {
    cout << ct[i] << ' ';
  }
  cout << endl;
  return 0;
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(std::string S) {
    if (S == "ABC") cout << "ARC" << endl;
    if (S == "ARC") cout << "ABC" << endl;
}

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


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

struct Data {
  int f,a,x,y;
  bool operator < ( const Data &data ) const {
    if( f != data.f ) return f < data.f;;
    if( a != data.a ) return a < data.a;;
    if( x != data.x ) return x < data.x;; 
    return y < data.y;;
  }
  bool operator == ( const Data &data ) const {
    return f == data.f && a == data.a && x == data.x && y == data.y;;
  }
};;

vector<Data> vec[2];;

#define pow2(x) ((x)*(x))
int main(){
  int n,f,a,t,x,y;;
  cin >> n;;
  rep(_,n){
    cin >> f >> a >> t >> x >> y;
    vec[t].push_back((Data){f,a,x,y});
  }
  rep(i,2) sort(vec[i].begin(),vec[i].end());
  double maxi[2] = {-1,-1};
  double time[2] = {-1,-1};
  
  rep(i,2) {
    rep(j,(int)vec[i].size()-1) {
      int p = lower_bound(vec[!i].begin(),vec[!i].end(),vec[i][j]) - vec[!i].begin();
      if( p < vec[!i].size() && vec[i][j].f < vec[!i][p].f && vec[!i][p].f < vec[i][j+1].f ) {
	continue;
      }
      
      if( vec[i][j].a != vec[i][j+1].a ) {
	double dist = sqrt(pow2(vec[i][j].x-vec[i][j+1].x)+pow2(vec[i][j].y-vec[i][j+1].y));
	if( equals(dist,maxi[i])  ) {
	  time[i] = min(time[i],(double)( vec[i][j+1].f - vec[i][j].f ) * 1.0/60.0);
	} else if (dist > maxi[i] ) {
	  maxi[i] = dist;	  
	  time[i] = (double)( vec[i][j+1].f - vec[i][j].f ) * 1.0/60.0;
	}
      }
    }
  }
  rep(i,2) printf("%.10f %.10f\n",maxi[i],time[i]);
   return 0;;
}

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

int main(){
    
    int n;
    cin >> n;
    vector<int> s(n);
    int sum=0;
    for(int i=0; i<n; i++){
        cin >> s.at(i);
        sum+=s.at(i);
    }

    sort(s.begin(),s.end());
    if(sum%10==0){
        int i=0;
        while(1){
            if(s.at(i)%10==0) i++;
            else{
                sum-=s.at(i);
                break;
            }
            if(i==n){
                sum=0;
                break;
            }
        }
    }
    cout << sum << endl;
}

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

int main() {
    int N, A[1000];
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];

    for(int i = 0; i < N / 2; i++) {
        int t = A[i];
        A[i] = A[N - 1 - i];
        A[N - 1 - i] = t;
    }

    for(int i = 0; i < N; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
}


Measured memory_bytes: 3088
#include<stdio.h>
short data[10001][721];
int main(void){
    while(1){
        int N,M,t,n,m,s,r,q,pc[1001]={0};
        //printf("test\n");
        scanf("%d%d",&N,&M);
        if(N+M==0) break;
        for(int i=0;i<=M;i++){
            for(int j=0;j<721;j++){
                data[i][j]=0;
            }
        }
        scanf("%d",&r);
        for(int i=0;i<r;i++){
            scanf("%d%d%d%d",&t,&n,&m,&s);
            if(s==1) pc[n]=t;
            else{
                for(int j=pc[n];j<t;j++){
                    data[m][j-540]=1;
                }
            }
        }
        scanf("%d",&q);
        for(int i=0;i<q;i++){
            int s,e,cnt=0;
            scanf("%d%d%d",&s,&e,&m);
            for(int j=s;j<e;j++){
                if(data[m][j-540]==1) cnt++;
            }
            printf("%d\n",cnt);
        }
    }
}



Measured memory_bytes: 15376
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int n;
int main()
{
	scanf("%d",&n);
	if(n==1)printf("1");
	if(n==2)printf("3");
	if(n==3)printf("4");
	if(n==4)printf("7");
	if(n==5)printf("11");
	if(n==6)printf("18");
	if(n==7)printf("29");
	if(n==8)printf("47");
	if(n==9)printf("76");
	if(n==10)printf("123");
	if(n==11)printf("199");
	if(n==12)printf("322");
	if(n==13)printf("521");
	if(n==14)printf("843");
	if(n==15)printf("1364");
	if(n==16)printf("2207");
	if(n==17)printf("3571");
	if(n==18)printf("5778");
	if(n==19)printf("9349");
	if(n==20)printf("15127");
	if(n==21)printf("24476");
	if(n==22)printf("39603");
	if(n==23)printf("64079");
	if(n==24)printf("103682");
	if(n==25)printf("167761");
	if(n==26)printf("271443");
	if(n==27)printf("439204");
	if(n==28)printf("710647");
	if(n==29)printf("1149851");
	if(n==30)printf("1860498");
	if(n==31)printf("3010349");
	if(n==32)printf("4870847");
	if(n==33)printf("7881196");
	if(n==34)printf("12752043");
	if(n==35)printf("20633239");
	if(n==36)printf("33385282");
	if(n==37)printf("54018521");
	if(n==38)printf("87403803");
	if(n==39)printf("141422324");
	if(n==40)printf("228826127");
	if(n==41)printf("370248451");
	if(n==42)printf("599074578");
	if(n==43)printf("969323029");
	if(n==44)printf("1568397607");
	if(n==45)printf("2537720636");
	if(n==46)printf("4106118243");
	if(n==47)printf("6643838879");
	if(n==48)printf("10749957122");
	if(n==49)printf("17393796001");
	if(n==50)printf("28143753123");
	if(n==51)printf("45537549124");
	if(n==52)printf("73681302247");
	if(n==53)printf("119218851371");
	if(n==54)printf("192900153618");
	if(n==55)printf("312119004989");
	if(n==56)printf("505019158607");
	if(n==57)printf("817138163596");
	if(n==58)printf("1322157322203");
	if(n==59)printf("2139295485799");
	if(n==60)printf("3461452808002");
	if(n==61)printf("5600748293801");
	if(n==62)printf("9062201101803");
	if(n==63)printf("14662949395604");
	if(n==64)printf("23725150497407");
	if(n==65)printf("38388099893011");
	if(n==66)printf("62113250390418");
	if(n==67)printf("100501350283429");
	if(n==68)printf("162614600673847");
	if(n==69)printf("263115950957276");
	if(n==70)printf("425730551631123");
	if(n==71)printf("688846502588399");
	if(n==72)printf("1114577054219522");
	if(n==73)printf("1803423556807921");
	if(n==74)printf("2918000611027443");
	if(n==75)printf("4721424167835364");
	if(n==76)printf("7639424778862807");
	if(n==77)printf("12360848946698171");
	if(n==78)printf("20000273725560978");
	if(n==79)printf("32361122672259149");
	if(n==80)printf("52361396397820127");
	if(n==81)printf("84722519070079276");
	if(n==82)printf("137083915467899403");
	if(n==83)printf("221806434537978679");
	if(n==84)printf("358890350005878082");
	if(n==85)printf("580696784543856761");
	if(n==86)printf("939587134549734843");
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, p, cnt = 0;
    cin >> N;
    for (int i = 0; i<N; i++) {
        cin >> p;
        if (p != i+1) {
            cnt++;
        }
    }
    printf("%s\n", cnt == 2 || cnt == 0 ? "YES" : "NO");
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

lli fn(lli x[], lli v[], lli c, const int N)
{
  lli y[N + 1];
  y[0] = 0;
  for (int i = 0; i < N; ++i) {
    y[i + 1] = y[i] + v[i];
  }
  for (int i = 0; i < N; ++i) {
    y[i + 1] -= (x[i] + x[i]);
    y[i + 1] = max(y[i + 1], y[i]);
  }

  lli mx = 0;
  
  lli sum = 0;
  for (int i = N - 1; 0 <= i; --i) {
    sum += v[i];
    lli z = sum - (c - x[i]) + y[i];
    mx = max(mx, z);
  }
  
  return mx;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  lli c;
  while (cin >> n >> c) {
    lli x[n];
    lli v[n];
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> v[i];
    }

    lli a = fn(x, v, c, n);

    reverse(x, x + n);
    reverse(v, v + n);
    for (int i = 0; i < n; ++i) {
      x[i] = c - x[i];
    }
    lli b = fn(x, v, c, n);

    cout << max(a, b) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 2560
# 1 "m.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "m.cpp"
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 1
       
# 12 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/bits/stdc++.h" 1
 #include <bits/stdc++.h>
# 13 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/assoc_container.hpp" 1
 #include <ext/pb_ds/assoc_container.hpp>
# 14 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/tree_policy.hpp" 1
 #include <ext/pb_ds/tree_policy.hpp>
# 15 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2







using namespace std;
using namespace __gnu_pbds;

using ii = pair<long long, long long>;
using vi = vector<long long>;
using vd = vector<long double>;
using vb = vector<bool>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvd = vector<vd>;
using vvb = vector<vb>;
using vvii = vector<vii>;
# 50 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
inline long long mod(const long long n, const long long m = ((long long)1e9+7)){
    return (n%m + m)%m;
}

/**
 * Euclidean GCD.
 *
 * Time Complexity: O(log(min(a, b))).
 * Space Complexity: O(log(min(a, b))).
 */
long long gcd(const long long a, const long long b){
    if(a < 0 or b < 0)
        return gcd(abs(a), abs(b));
    if(a == 0)
        return b;
    return gcd(b%a, a);
}

/**
 * Euclidean derivated LCM.
 *
 * Time Complexity: O(log(min(a, b))).
 * Space Complexity: O(log(min(a, b))).
 */
long long lcm(const long long a, const long long b){
    // same as a*b/gcd(a, b) but avoiding overflow.
    return a/gcd(a, b)*b;
}
# 2 "m.cpp" 2

int32_t main(){
    (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL));
    long long n, k;
    cin >> n >> k;
    vi arr(n);
    for(long long &i:arr)
        cin >> i;
    reverse(arr.begin(), arr.end());
    vvi dp(2, vi(k+1));
    dp[1][0] = 1;
    for(long long i:arr){
        for(long long j=0; j<=k; ++j){
            dp[0][j] = 0;
            if(j)
                dp[1][j] = mod(dp[1][j] + dp[1][j-1]);
        }
        for(long long j=0; j<=k; ++j){
            long long l = max((long long)0, j-i);
            dp[0][j] = dp[1][j];
            if(l)
                dp[0][j] = mod(dp[0][j] - dp[1][l-1]);
        }
        swap(dp[0], dp[1]);
    }
    cout << dp[1][k] << "\n";
    return 0;
}


Measured memory_bytes: 2560
// g++ -std=c++14
#include<bits/stdc++.h>
typedef long long int lli;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x);
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z);

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) c.begin(),c.end()

#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main(){
  _
  int n;
  cin >> n;
  double t,a;
  cin >> t >> a;
  double arr[n];
  for(int i=0;i<n;i++){
    cin >> arr[i];
  }
  double dif = abs(t - arr[0]*0.006-a);
  int ind = 0;
  for(int i=1;i<n;i++){
    double temp = abs(t-arr[i]*0.006-a);
    if(temp<dif){
      dif = temp;
      ind = i;
    }
  }
  cout << ind+1 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  string s;cin>>s;
  int sz=s.size();
  for(int i=0;i<sz-8;i++)
    cout<<s[i];
  cout<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
				ans += 2;
			} else if (a[i] == b[i] && b[i] == c[i]) {
				
			} else {
				ans += 1;
			}
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int n,k;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s>>k;
	for (int i=0;i<s.size();++i)
	{
		if (s[i]!=s[k-1]) cout<<"*";
		else cout<<s[i];
	}
	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;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  priority_queue<int> que;
  que.push(a[0]);
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    int p = que.top();
    que.pop();
    ans += p;
    rep(_, 2)
      que.push(a[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5016
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int[]xyz=new int[3];
        for(int i=0;i<n;i++) {
            int[]XYZ=new int[3];
            int[]abc=Console.ReadLine().Split().Select(int.Parse).ToArray();
            for(int j=0;j<3;j++){
                for(int k=0;k<3;k++){
                    if(j==k)continue;
                    Chmax(ref XYZ[j],xyz[k]+abc[j]);
                }
            }
            xyz=XYZ;
        }
        int ans=0;
        for(int i=0;i<3;i++){
            Chmax(ref ans, xyz[i]);
        }
        Console.WriteLine(ans);
    }
    public static void Chmax(ref int x, int y) {
        x = Math.Max(x, y);
    }
}



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

int main() {
    int c[3][3];
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    rep(a1, 101) rep(a2, 101) rep(a3, 101) {
        bool ok = true;

        rep(i, 3) {
            int b1 = c[0][i] - a1;
            int b2 = c[1][i] - a2;
            int b3 = c[2][i] - a3;
            if (!(b1 == b2 && b2 == b3 && b1 == b3)) ok = false;
        }

        if (ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


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


int main() {
    Int N;
    cin >> N;
    vector<Int> L(N);
    rep(i,N) cin >> L[i];
    sort(L.begin(),L.end());

    Int ans = 0;
    rep(i,N-2) {
        for (int j = i+1; j<N-1; j++) {
            auto left = upper_bound(L.begin()+j+1, L.end(), L[j]-L[i]);
            auto right = lower_bound(L.begin()+j+1, L.end(), L[i] + L[j]);

            ans += right - left;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double pi=acos(-1);
int main(){
    cout<<fixed<<setprecision(20);
    double a,b,x;
    cin>>a>>b>>x;
    if(a*a*b/2<= x)cout<<180.0*atan(2*(a*a*b-x)/(a*a*a))/pi<<endl;
    else cout<<180.0*atan(a*b*b/(2*x))/pi<<endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
  input! {
    s: usize, w: usize
  };

  let res = if w >= s { "unsafe" } else { "safe" };
  println!("{}", res);
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    int l = 1000; int r = 0;
    rep(i,n){
        int a; cin >> a;
        l = min(l,a); r = max(r,a);
    }
    cout << r-l << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
Ss = [[1], [1]]
while True:
    k = len(Ss)
    m = k * (k - 1) // 2
    if N < m:
        print("No")
        break
    elif N == m:
        print("Yes")
        print(k)
        for S in Ss:
            print(len(S), " ".join(map(str, S)))
        break
    S_new = []
    for i in range(k):
        x = m + 1 + i
        Ss[i].append(x)
        S_new.append(x)
    Ss.append(S_new)

Measured memory_bytes: 8948