akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

  int N; cin>>N;
  multiset<int> S;
  for (int i = 0; i < (1<<N); i++) {
    int s; cin>>s;
    S.insert(-s);
  }

  vector<int> V;
  auto maxs = *(S.begin());
  S.erase(S.begin());
  V.push_back(maxs);
  for (int i = 0; i < N; i++) {
    for (int n = 0; n < (1<<i); n++) {
      int q = V[n];
      auto tg = S.upper_bound(q);
      if (tg == S.end()) {
        // Failure
        cout << "No" << endl;
        return 0;
      }
      int maxs = *tg;
      S.erase(tg);
      V.push_back(maxs);
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 13688
d, n = map(int, input().split())

if d==0:
    if n==100:
        print(1+n)
    else:
        print(n)

elif d==1:
    if n==100:
        print(100+100*n)
    else:
        print(100*n)

else:
    if n==100:
        print(10000+10000*n)
    else:
        print(10000*n)

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

using namespace std;

struct Sieve {
    int sz;
    vector<bool> is;
    vector<int> prime;
    Sieve(int n = 45000):sz(n) {
        prime.reserve(n/6);
        is.assign(n+1, true);
        is[0] = is[1] = false;
        for (int p = 2; (int64_t)p*p <= n; p++) {
            if (is[p]) {
                for (int i = p*p; i <= n; i += p) {
                    is[i] = false;
                }
            }
        }
        for (int i = 2; i <= n; i++) {
            if (is[i])
                prime.emplace_back(i);
        }
    }
};
const int N = 100005; 
int a[N];

void pre(){
    Sieve s(N);
    for (int i = 3; i <= 100000; i++) {
        a[i] = a[i-1];
        if (s.is[i] && s.is[(i+1)/2]) {
            a[i] += 1;
        }
    }
}

void solve() {
    pre();
    int q; cin >> q;
    while (q--) {
        int l,r;
        cin >> l >> r;
        l = max(l,3);
        if (l > r) {
            cout << "0\n";
        }else{
            cout << (a[r]-a[l-1]) << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1152
ans [x,y] =
  let g = gcd x y
      x'= x `div` g
      y'= y `div` g
  in
    (x'-1+y'-1+1) * g + 1

main = do
  l <- getLine
  let i = map read $ words l :: [Int]
      o = ans i
  print o
  

Measured memory_bytes: 3644
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto x = readln.chomp.split;
  auto a = x[0].to!int;
  auto b = x[2].to!int;

  if (x[1] == "+") {
    writeln(a+b);
  } else {
    writeln(a-b);
  }
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
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.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
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
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
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
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
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)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

proper t (a,b,_) = a<=t && t<=b
hade (_,_,c) = c

f :: [(Int,Int,Int)] -> [(Int,Int)] -> Int -> [(Int,Int)]
f cs ss t = [(hade c, maximum [a + abs (h - hade c) | (h,a) <- ss]) | c <- cs, proper t c]

main = do
    [d,n] <- getInts
    (ti:ts) <- replicateM d getInt
    rs <- map (apply3 (,,)) <$> replicateM n getInts
    let firstChoice = [(hade r, 0) | r <- rs, proper ti r]
    print $ maximum $ map snd $ foldl (f rs) firstChoice ts
    return ()

Measured memory_bytes: 8224
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 10000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,k,q ;
	cin >> n >> k >> q ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	vll b = a ;
	mysort(b) ;
	ll ans = b.at(q-1)-b.at(0) ;
	set<int> s ;
	for(int i=1;i<n;i++){
		if(b.at(i)==b.at(i-1)) continue ;
		vll c(0),sub(0),none(0) ;
		for(int j=0;j<n;j++){
			if(a.at(j)==b.at(i-1)) s.insert(j) ;
		}
		int cnt = 0 ;
		for(int j=0;j<n;j++){
			if(s.count(j)){
				if(cnt<k){
					cnt = 0 ;
					sub = none ;
				}else{
					mysort(sub) ;
					for(int l=0;l<min(q,cnt-k+1);l++){
						c.emplace_back(sub.at(l)) ;
					}
					sub = none ;
					cnt = 0 ;
				}
			}else{
				cnt++ ;
				sub.emplace_back(a.at(j)) ;
			}
		}
		if(sub.size()>0){
			mysort(sub) ;
			for(int j=0;j<min(q,cnt-k+1);j++){
				c.emplace_back(sub.at(j)) ;
			}
		}
		if(c.size()<q) break ;
		mysort(c) ;
		ans = min(ans,c.at(q-1)-c.at(0)) ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 384
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

bool solve() {
  int a, b, c;
  if (scanf("%d%d%d", &a, &b, &c) != 3) { return false; }

  printf("%s\n", (a == b && b == c ? "Yes" : "No"));
  return true;
}

int main() {
  while (solve());
  return 0;
}

Measured memory_bytes: 256
//Be Name Khoda
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e6 + 7;
int a[MAXN], b[MAXN];
set<int> S;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[a[i]]++;
		S.insert(a[i]);
	}
	int evens = 0;
	for (int i = 0; i < MAXN; i++)
		if(b[i] % 2 == 0 and b[i])
			evens++;
	if(evens % 2 == 0)
		cout << S.size();
	else
		cout << S.size() - 1;
}

Measured memory_bytes: 9472
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int d[1000000];
int main()
{
   ll n,i;
  cin>>n;
  ll s=0;
  for(i=0;i<=n-1;i++)
  s+=i;
  cout<<s<<endl;
}

Measured memory_bytes: 384
let k, t = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init t @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Printf.printf "%d\n" @@ max 0 @@ 2 * Array.fold_left max a_s.(0) a_s - k - 1

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


int main(){
    string a,b,c; cin >> a >> b >> c;
    cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n, k, s;
  cin >> n >> k >> s;

  vector<int> ans(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    ans[i] = s;
  }

  for (int i = 0; i < (n - k); i++) {
    ans[i] = s - 1;
    if(s == 1 || s == 2) {
      ans[i] = 1000000;
    }
  }

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

  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll dp[1000001];

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

    vector<int> wi(n), vi(n);
    for (int i=0; i<n; i++) {
        cin >> wi[i] >> vi[i];
    }

    for (int i = 0; i <= w; i++) {
        dp[i] = -1;
    }
    dp[0] = 0;
    dp[wi[0]] = vi[0];

    for (int i = 1; i < n; i++) {
        for (int j=w; j>=0; j--) {
            if (dp[j] != -1) {
                if (j + wi[i] <= w && dp[j+wi[i]] < dp[j] + vi[i]) {
                    dp[j+wi[i]] = dp[j] + vi[i];
                }
            }
        }
    }

    ll maxval = 0;
    for (int i=0; i<=w; i++) {
        if (maxval < dp[i]) {
            maxval = dp[i];
        }
    }

    cout << maxval << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
		boolean bRet = false;
		try {
			bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
		} catch (IOException e) {
		}
		return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			String sam = "sample"+sample;
			String ans = "answer"+sample;
			String res = "result"+sample;
			if(fileCompare2(ans, res)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
				try {
					System.out.println(new String(Files.readAllBytes(Paths.get(ans))));
					System.out.println(new String(Files.readAllBytes(Paths.get(res))));
					System.out.println(new String(Files.readAllBytes(Paths.get(sam))));
				} catch (IOException e) {
				}
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		try {
			final int N = sc.nextInt();
			final int D = sc.nextInt();
			out.println(N/(2*D+1)+(N%(2*D+1)==0?0:1));
		} finally {
			exit();
		}
	}
}


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

int main()
{

  int i,j,k=0,l,n;
  string a;
cin>>a;
  n=a.length();

  for(i=0;i<n;i++)
  {
    if(a[i]=='7')
    {k=1;
     break;
    }

  }
  if(k==1)
cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;

}


Measured memory_bytes: 3596
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    n_multiple = [0] * (K + 1)
    for k in range(1, K + 1):
        n_multiple[k] = K // k

    n_gcd = [0] * (K + 1)
    for k in reversed(range(1, K + 1)):
        n_gcd[k] = pow(n_multiple[k], N, mod=P)
        m = 2
        kk = k * m
        while kk <= K:
            n_gcd[k] = (n_gcd[k] - n_gcd[kk]) % P
            m += 1
            kk = k * m

    ans = 0
    for k in range(1, K + 1):
        ans = (ans + k * n_gcd[k]) % P
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11992
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  bool zero_exists = false;
  int64_t minv = INT64_MAX;
  int64_t sum = 0;
  int minus_cnt = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0)
      zero_exists = true;
    if (A[i] < 0) {
      A[i] = -A[i];
      minus_cnt++;
    }
    if (A[i] != 0)
      minv = min({minv, A[i]});
    sum += A[i];
  }
  if (zero_exists || minus_cnt % 2 == 0)
    cout << sum << endl;
  else
    cout << sum - 2*minv << endl;
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<ll> v(5);
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        if(s[0] == 'M') v[0]++;
        if(s[0] == 'A') v[1]++;
        if(s[0] == 'R') v[2]++;
        if(s[0] == 'C') v[3]++;
        if(s[0] == 'H') v[4]++;
    }
    ll ans = 0;
    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 4; j++){
            for(int k = j + 1; k < 5; k++){
                ans += v[i] * v[j] * v[k];
            }
        }
    }
    cout << ans << endl;
}


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

int sum;

bool nijyou(int sum){
  for(int i=0;i<1000;i++){
    if(sum == i*i)return true;
  }
  return false;
}

int main(){
  int n,d,minus = 0,nijou = 0,ans = 0;
  sum = 0;
  cin >> n >> d;
  int x[n][d];
  for(int i = 0;i < n;i++){
    for(int j = 0;j < d;j++){
      cin >> x[i][j];
    }
  }
  for(int i = 0;i < n;i++){
    for(int k = i + 1;k < n;k++){
      for(int j = 0;j < d;j++){
        minus = abs(x[i][j] - x[k][j]);
        nijou = minus*minus;
        sum += nijou;
      }
      if(nijyou(sum)) ans += 1;
      sum = 0,nijou = 0,minus = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
m = 10**9+7
d = {}

for i in range(2, n+1):
  tmp = i
  div = 2
  while tmp > 1:
    if tmp % div == 0:
      if div not in d:
        d[div] = 1
      else:
        d[div] += 1
      tmp //= div
    else:
      div += 1

ans = 1
for div in d:
  ans = ans * (d[div] + 1) % m

print(ans)

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

const int N = 1e5+55;

int sz[N] , p[N];

int get(int v) {
	if(p[v] == v) return v;
	return p[v] = get(p[v]);
}

int merge(int a , int b) {
	a = get(a) , b = get(b);
	if(a == b) return 0;
	if(sz[a] < sz[b]) swap(a , b);
	sz[a] += sz[b];
	p[b] = a;
	return 1;
}

int main() {
	int n , m;
	cin >> n >> m;
	int ans = n-1;
	for(int i = 1; i <= n; i ++) {
		sz[i] = 1;
		p[i] = i;
	}
	for(int i = 1; i <= m; i ++) {
		int a,  b;
		cin >> a >> b;
		ans -= merge(a , b);
	}
	cout << ans;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N < 10){
    cout << N << endl;
  }else if (N < 100){
    cout << 9 << endl;
  }else if (N < 1000){
    cout << (N - 100 + 1) + 9;
  }else if (N < 10000){
    cout << 9 + (999 - 100 + 1);
  }else if (N < 100000){
    cout << (N - 10000 + 1 ) + 9 + (999 - 100 + 1);
  }else{
    cout << 90909;;
  }
}

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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << '\n';


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    priority_queue<double,vector<double>,greater<double> > pq;
    for(int i=0;i<N;i++){
        cin >> v[i];
        pq.push(double(v[i]));
    }
    //sort(v.begin(),v.end());
    double ans=0;
    
    for(int i=1;i<N;i++){
        double p=pq.top(); pq.pop();
        double q=pq.top(); pq.pop();
        double res=(p+q)*1.0/2;
        //cout << res << endl;
        ans=res;
        pq.push(res);
    }
    printf("%.8f\n",ans);
    
}


Measured memory_bytes: 256
def function(n):
    if n%2 == 0:
        return int(n/2)
    else:
        return 3*n + 1

s = int(input())
a = [s] #数列
i = 0 #進行マーカー(数列の添え字に対応)
flag = -1 #printするmの値をここにいれる
while flag == -1:#同じのが数列上に現れた時点でbreak
    another = function(a[i])#次のやつを算出
    for j in range(len(a)):#ダブってないかチェック
        if another == a[j]:#ダブってったらflagに記録してbreak
            flag = i + 2
            break
    a.append(function(a[i]))#数列に追加
    i = i + 1#次の項へ
print(flag)





Measured memory_bytes: 3060
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e9+7;
const ll MAXN=1000200;
ll i,j,mask,test;
vector<ll> fact(MAXN),inv(MAXN);
ll power(ll n,ll x)
{
    ll res=1,p=n;
    while(x>0)
    {
        if(x%2==1)
        {
            res=((res%mod)*(p%mod))%mod;
        }
        x/=2;
        p=((p%mod)*(p%mod))%mod;
    }
    return res;
}
void initializer()
{
    fact[0]=1;
    F(i,1,1000001)
    {
        fact[i]=(fact[i-1]*i)%mod;
    }
    RF(i,1000000,1)
    {
        inv[i]=power(fact[i],mod-2);
    }
}
ll C(ll n,ll r)
{
    ll k=(fact[n]*inv[r])%mod;
    k=(k*inv[n-r])%mod;
    return k;
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
initializer();
ll n;
cin>>n;
ll ans=power(10,n)%mod;
ans=(ans-power(8,n))%mod;
if(ans<0)
    ans+=mod;
    ll p=0;
for(i=1;i<n;i++)
{
    p=(p+(C(n,i)*power(8,n-i))%mod)%mod;
    if(p<0)
        p+=mod;
}
p++;
p*=2;
p%=mod;
//cout<<p;nl

ans-=p;
if(ans<0)
    ans+=mod;
cout<<ans;
return 0;
}


Measured memory_bytes: 18672
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

mod = 10 ** 9 + 7
vx = sum((2 * (k + 1) - N - 1) * X[k] % mod for k in range(N)) % mod
vy = sum((2 * (k + 1) - M - 1) * Y[k] % mod for k in range(M)) % mod
print(vx * vy % mod)


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

using namespace std;

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

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if (s == "A") {
            cnt++;
        } else {
            if (cnt == 0) {
                cnt = -1; break;
            }
            cnt--;
        }
    }

    cout << (cnt == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    map<string, string> a;
    a.insert({"Sunny", "Cloudy"});
    a.insert({"Cloudy", "Rainy"});
    a.insert({"Rainy", "Sunny"});

    cout << a[s] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int submit[31]={0};
  int i;
  int k;

  for(k=0;k<28;k++){
    scanf("%d",&i);
    submit[i]=1;
  }

  for(k=1;k<=30;k++){
    if(submit[k]==0){
      printf("%d\n",k);
    }
  }

  return 0;

}

Measured memory_bytes: 596
k,n=map(int,input().split())
a=list(map(int,input().split()))
distance=[0]*n
for i in range(n):
  if i==n-1:
    distance[i]=k+a[0]-a[i]
  else:
    distance[i]=a[i+1]-a[i]
m=0
for i in distance:
  if m<i:
    m=i
print(k-m)

Measured memory_bytes: 26420
#include <stdio.h>

int main(void)
{
    int n,m,x,a,l=0,r=0,i;
    scanf("%d%d%d",&n,&m,&x);
    for(i=0;i<m;i++){
        scanf("%d",&a);
        if(a>x)r++;
        else l++;
    }
    printf("%d",r>l?l:r);
    return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      lrs: [(i64, i64); n],
    }
    let lrs: Vec<_> = lrs.into_iter().map(|(l, r)| (l, r+1)).collect();

    let max_l = lrs.iter().map(|v|v.0).max().unwrap();
    let min_r = lrs.iter().map(|v|v.1).min().unwrap();

    let max_range = lrs.iter().map(|v| v.1 - v.0).max().unwrap();
    let ans1 = max_range + max(min_r - max_l, 0);


    let mut abs = lrs.into_iter().map(|(l, r)| {
            (
                max(r - max_l, 0),
                max(min_r - l, 0),
            )
        })
        .collect::<Vec<_>>();
    abs.sort_by_key(|v| (v.0, -1 * v.1));

    let (_, mut min_b) = abs[0];
    let (mut min_a, _) = abs[1];
    let mut ans2 = min_a + min_b;
    for i in 1..(n - 1) {
        let (_, b) = abs[i];
        min_b = min(min_b, b);
        let (a, _) = abs[i + 1];
        min_a = a;
        ans2 = max(ans2, min_a + min_b);
    }
    puts!("{}\n", max(ans1, ans2));
}


Measured memory_bytes: 10492
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

string name(long long n) {
	string s;
	while (n > 0) {
// printf("n %10lld\n", n);
		s += ((n - 1) % 26) + 'a';
		n--;
		n /= 26;
	}
	reverse(s.begin(), s.end());

	return s;
}

void check() {
	for (int i = 1; i <= 28; i++) {
		auto s = name(i);
		printf("%5d: %10s\n", i, s.c_str());
	}

	for (int i = 700; i <= 710; i++) {
		auto s = name(i);
		printf("%5d: %10s\n", i, s.c_str());
	}

	for (int i = 18277; i <= 18271; i++) {
		auto s = name(i);
		printf("%5d: %10s\n", i, s.c_str());
	}

}

int main() {
	long long n;
	cin >> n;

	string ans = name(n);
	cout << ans << endl;

	// check();


	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var AC = 0;
            var WA = 0;
            var TLE = 0;
            var RE = 0;
            for (int i = 0; i < N; i++)
            {
                var s = Read();
                switch (s)
                {
                    case "AC":
                        AC++;
                        break;
                    case "WA":
                        WA++;
                        break;
                    case "TLE":
                        TLE++;
                        break;
                    case "RE":
                        RE++;
                        break;
                    default:
                        break;
                }
            }
            WriteLine("AC x " + AC);
            WriteLine("WA x " + WA);
            WriteLine("TLE x " + TLE);
            WriteLine("RE x " + RE);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define p pair<int,int>
#define mp(a, b) make_pair(a,b)
#define ll long long
using namespace std;

class Unionfind {
    vector<int> par;
public:
    vector<int> size;

public:
    void init(int n) {
        par = vector<int>(n);
        size = vector<int>(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            size[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

public:
    void unite(int x, int y) {
        if (issame(x, y)) return;
        x = root(x);
        y = root(y);
        par[x] = y;
        int sum = size[x] + size[y];
        size[x] = sum;
        size[y] = sum;
    }

public:
    bool issame(int x, int y)//同じ集合に属しているか
    {
        return root(x) == root(y);
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<p > pa;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        pa.push_back(mp(a, b));
    }
    reverse(pa.begin(), pa.end());
    Unionfind uf;
    uf.init(n + 1);
    ll count = n * (n - 1) / 2;
    vector<ll> ret;
    for (int i = 0; i < m; i++) {
        ret.push_back(count);
        auto _ = pa[i];
        int f = _.first;
        int s = _.second;
        if (!uf.issame(f, s)) {
            count -= uf.size[uf.root(f)] * uf.size[uf.root(s)];
            uf.unite(f, s);
        }
    }
    reverse(ret.begin(), ret.end());
    for (auto x:ret) cout << x << endl;
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> cnt(N+1);
    REP(i,N-1){
        int a;
        cin >> a;
        cnt[a]++;
    }
    for(int i=1;i<=N;i++) cout << cnt[i] << endl;
}


Measured memory_bytes: 3972
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[55];
int n;
vector<string> v;

bool isAIUEO(char c){
	if(c=='a')return 1;
	if(c=='i')return 1;
	if(c=='u')return 1;
	if(c=='e')return 1;
	if(c=='o')return 1;
	return 0;
}

void F(string a,int t){
	string ret="",put="";ret+=a[0];
	for(int i=0;i<a.size()-1;i++){
		if(isAIUEO(a[i]))ret+=a[i+1];
	}
	int deg=(ret.size()<t)?ret.size():t;
	for(int i=0;i<deg;i++)put+=ret[i];
	v.push_back(put);
}

int main(){
	while(cin>>n&&n){
	rep(i,n)cin>>s[i];
	int k=1;
	while(true){
		v.clear();
		rep(i,n)F(s[i],k);
		sort(v.begin(),v.end());
		bool ok=true;
		rep(i,n-1)if(v[i]==v[i+1])ok=false;
		if(ok)break; k++;
		if(k==100){k=-1;break;}
	}cout<<k<<endl;
	}
	return 0;
}

Measured memory_bytes: 3136
import java.util.Scanner;

/**
 * B - Substring
 * 2 つの文字列 S, T が与えられます。
 * T が S の部分文字列となるように、S のいくつかの文字を書き換えます。
 * 少なくとも何文字書き換える必要がありますか？
 * ただし、部分文字列とは連続する部分列のことを指します。例えば、xxx は yxxxy の部分文字列ですが、xxyxx の部分文字列ではありません。
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        String s = sc.next();
        String t = sc.next();

        int result = t.length();
        for( int i = 0; i < s.length() - ( t.length() - 1 ); i++ ) {
            int charCnt = 0;
            String subStr = s.substring( i, i + t.length() );
            if( subStr.equals( t ) ) {
                result = 0;
                break;
            }
            else {
//                char[] temp = new char[t.length()];
                for( int j = 0; j < t.length(); j++ ) {
//                    temp[j] = subStr.charAt(j);
                    if( t.charAt( j ) != subStr.charAt( j ) ) ++charCnt;
                }
            }
            if( result > charCnt ) result = charCnt;
        }

        System.out.println( result );

        sc.close();
    }
}


Measured memory_bytes: 37140
a, b, c, x, y = map(int, input().split())

ans = 10 ** 18
for i in range(0, 2 * max(x, y) + 1, 2):
    tmp = i * c
    if x - i // 2 > 0:
        tmp += (x - i // 2) * a
    if y - i // 2 > 0:
        tmp += (y - i // 2) * b
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 39280
#!/usr/bin/env python
#coding: UTF-8
import sys
import math

i= sys.stdin.readline()

a,b,c = map(int,i.split())

d = math.cos(math.radians(c))
c = math.sin(math.radians(c))

S = 0.5*a*b*c
L = math.sqrt(a**2+b**2-2*a*b*d)+a+b
h = S*2/a

print S,L,h

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

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

    int N;
    cin >> N;
    int a[N];
    for (int i=0; i<N; i++) cin >> a[i];
    int rate[] = {0, 0, 0, 0, 0, 0, 0, 0};
    int top = 0;
    for (int i=0; i<N; i++) {
        if (a[i] < 400) rate[0]++;
        else if (a[i] < 800)  rate[1]++;
        else if (a[i] < 1200) rate[2]++;
        else if (a[i] < 1600) rate[3]++;
        else if (a[i] < 2000) rate[4]++;
        else if (a[i] < 2400) rate[5]++;
        else if (a[i] < 2800) rate[6]++;
        else if (a[i] < 3200) rate[7]++;
        else top++;
    }
    int mn = 0;
    for (int i=0; i<8; i++) {
        if (rate[i] > 0) mn++;
    }
    cout << max(1, mn) << " " << mn+top << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))
if (0 in x):
    k-=1
else:
    x.append(0)
    x.sort()

zeroPos=x.index(0)
leftLen=zeroPos
rightLen=len(x)-zeroPos-1
# print(leftLen,zeroPos,rightLen)
# print(x)
left=[]
right=[]
for turn in range(leftLen+1):
    if(turn>k):
        break
    if(k-turn<=rightLen):
        left.append(x[zeroPos-turn]*-2 + x[zeroPos+k-turn])
for turn in range(rightLen+1):
    if(turn>k):
        break
    if(k-turn<=leftLen):
        right.append(2*x[zeroPos+turn] + -1*x[zeroPos-k+turn])
minL=min(left)
minR=min(right)
# print(left,right)
print(minL if minL<minR else minR)

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


void solve(ll N, ll K)
{
    ll g = N%K;
    cout<<min(g,K-g)<<endl;
}


int main()
{
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    solve(N, K);
    return 0;
}


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

int main() {
  int intA, intB;
  cin >> intA >> intB;

  if ((intA % 2) == 0) {
    cout << "Even" << endl;
  }
  else if ((intB % 2) == 0) {
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }    

}


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

struct TinyStack {
  int S[101]; // データを格納するための整数型1次元配列
  int top;    // スタックポインタを表す整数型変数

  // コンストラクタ
  TinyStack() {
    top = 0;
  }
  // スタックに要素 x を追加する関数
  void push(int x) {
    top++;
    S[top] = x;
  }
  // スタックのトップから要素を取り出す関数
  int pop() {
    int val = S[top];
    top--;
    return val;
  }
};

bool is_number(string s) {
  auto condition = [](char c) {
    return isdigit(c);
  };
  return all_of(s.begin(), s.end(), condition);
}

void calc(TinyStack &sk, string op) {
  int right = sk.pop();
  int left = sk.pop();

  int result = 0;
  if (op == "+") {
    result = left + right;
  } else if (op == "-") {
    result = left - right;
  } else if (op == "*") {
    result = left * right;
  }

  // cout << left << " " << op << " " << right << " = " << result << endl;
  sk.push(result);
}

int main() {
  TinyStack sk;
  string symbol;

  while (cin >> symbol) {
    // オペランドの場合
    if (is_number(symbol)) {
      sk.push(stoi(symbol));
    // 演算子の場合
    } else {
      calc(sk, symbol);
    }
  }

  cout << sk.pop() << endl;
  return 0;
}



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

int main() {
  long n,ans=9999999999;
  string s;
  cin >> n >> s;
  vector<long> wcost(n+1),bcost(n+1);
  for(long i=1;i<=n;i++) {
    if(s[i-1]=='.') wcost[i]=wcost[i-1];
    else wcost[i]=wcost[i-1]+1;
  }
  for(long i=n-1;i>=0;i--) {
    if(s[i]=='#') bcost[i]=bcost[i+1];
    else bcost[i]=bcost[i+1]+1;
  }
  for(long i=0;i<=n;i++) ans=min(ans,wcost[i]+bcost[i]);
  cout << ans << endl;
}

Measured memory_bytes: 6824
#include<iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include <functional>
using namespace std;

int main(void) {
	int ans = 0, max = 0;;
	int N;
	int H[100] = { 0 };

	cin >>N;
	for (int i = 0; i < N;i++)
		cin >> H[i];
	max = H[0];
	ans = 1;
	for (int i = 1;i < N;i++) {
		if (max <= H[i]) {
			max = H[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

vector<ll> dy = {1,0,-1,0};
vector<ll> dx = {0,1,0,-1};


int main(){
  ll h,w;cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a.at(i);
  //そのマスが黒くなるまでの操作数
  vector<vector<ll>> dist(h,vector<ll>(w,-1));

  queue<P> q;
  auto push = [&]( ll y, ll x, ll d ){
    //すでに探索済みなら操作しない
    if( dist.at(y).at(x) != -1 ) return;
    //操作数を更新
    dist.at(y).at(x) = d;
    q.push(make_pair(y,x));
  };
  //1回目の操作
  for(ll i=0;i<h;++i){
    for(ll j=0;j<w;++j){
      if( a.at(i).at(j) == '#' ){
        push(i,j,0);
      }
    }
  }

  while( !q.empty() ){
    P p = q.front();q.pop();
    ll d = dist.at(p.first).at(p.second);
    for(ll i=0;i<4;++i){
      ll ny = p.first + dy.at(i);
      ll nx = p.second + dx.at(i);
      if( ny >= 0 && ny < h && nx >= 0 && nx < w ){
        push(ny,nx,d+1);
      }
    }
  }

  ll ans = -10;
  rep(i,h){
    rep(j,w){
      ans = max(ans,dist.at(i).at(j));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 29252
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  int N; cin >> N ;
  vi a(N);
  rep(i,N) cin >> a[i] ;
  int mi = *min_element(ALL(a));
  int ma = *max_element(ALL(a));
  if(ma-mi>1){
    cout << "No" << endl;
  }else if(mi==ma){
    if(mi==N-1||2*mi<=N) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else{
    int k = 0;
    rep(i,N) if(a[i]==mi) k++;
    if(mi-k+1>=1 && 2*(mi-k+1)<=N-k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

int n;

int a[100002];

map<int, int> mp;

struct UF{
	vector<int> belong;
	vector<int> size;
	void resize(int n){
		belong.assign(n + 1, -1);
		size.assign(n + 1, 1);
	}
	inline int root(int b){
		if (belong[b] == -1){
			return b;
		}
		belong[b] = root(belong[b]);
		return belong[b];
	}
	void merge(int a, int b){
		a = root(a);
		b = root(b);
		if (a == b)return;
		belong[a] = b;
		size[b] += size[a];
	}
};
UF uf;

int main(){
	uf.resize(100002);
	cin >> n;
	int t;
	cin >> t;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int mint = INT_MAX;
	int maxx = 0;
	for (int i = 0; i < n; i++){
		mint = min(mint, a[i]);
		maxx = max(maxx, a[i] - mint);
	}
	int mint2 = INT_MAX;
	int maxx2 = 0;
	int cnt = 0;
	for (int i = 0; i < n; i++){
		mp[a[i]] = i;
		int k = (*mp.begin()).first;
		if (a[i] - k == maxx){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 6144
import java.io.InputStream;
import java.util.*;


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

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int nCoeff = 0;
        int mCoeff = 0;

        if (n > 1) {
            nCoeff = binomialCoefficient(n, 2);
        }

        if (m > 1) {
            mCoeff = binomialCoefficient(m, 2);
        }

        System.out.println(nCoeff + mCoeff);
    }

    private static int binomialCoefficient(int n, int k) {
        int coefficient = 1;

        if (k > n - k) {
            k = n - k;
        }

        for (int i = 0; i < k; ++i) {
            coefficient *= (n - i);
            coefficient /= (i + 1);
        }

        return coefficient;
    }
}

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

//木を実装する
typedef struct _node{
    int element;
    struct _node *left;
    struct _node *right;
    struct _node *par;
}node;

typedef struct _tree{
    node *root;
}tree;

//リストを生成する関数
tree *create(){
    tree *T = (tree *)malloc(sizeof(tree));
    T->root = (node *)malloc(sizeof(node));
    T->root->left = NULL;
    T->root->right = NULL;
    T->root->par = NULL;
    T->root->element = -1;
    return T;
}

void make_tree(tree *T, string s){
    node *ptr = T->root;

    for(int i = 0; i < (int) s.size(); i++){

        if(s[i] == '('){
            //どっちかににノードを足す
            node *add = (node *)malloc(sizeof(node));
            add->element = -1;
            add->left = NULL;
            add->right = NULL;
            add->par = ptr;

            //左
            if(ptr->left == NULL){
                ptr->left = add;
                ptr = add;
            }else{
                ptr->right = add;
                ptr = add;
            }
        }else if(s[i] == ')'){
            //戻る
            ptr = ptr->par;
        }else if(s[i] == '['){
            string str;
            int j;
            for(j = i + 1; s[j] != ']'; j++) str.push_back(s[j]);
            int num = stoi(str);
            ptr->element = num;
            i = j;
        }
    }
}

void print_tree(node *v){
    if(v == NULL || v->element == -1){
        cout << ")";
        return;
    }

    cout << "(";
    print_tree(v->left);
    cout << "[" << v->element << "]";
    cout << "(";
    print_tree(v->right);
    if(v->par != NULL) cout << ")";
    return;
}

void sum_tree(node *v1, node *v2, node *v3){
    v3->element = v1->element + v2->element;

    if(v1->left != NULL && v2->left != NULL && v1->left->element != -1 && v2->left->element != -1){
        node *add = (node *)malloc(sizeof(node));
        add->element = -1;
        add->left = NULL;
        add->right = NULL;
        add->par = v3;
        v3->left = add;
        sum_tree(v1->left, v2->left, v3->left);
    }
    
    if(v1->right != NULL && v2->right != NULL && v1->right->element != -1 && v2->right->element != -1){
        node *add = (node *)malloc(sizeof(node));
        add->element = -1;
        add->left = NULL;
        add->right = NULL;
        add->par = v3;
        v3->right = add;        
        sum_tree(v1->right, v2->right, v3->right);
    }
    
    //if(v->par != NULL) cout << ")";
    return;
    
}

int main(){

    string s1, s2; cin >> s1 >> s2;
    tree *T1 = create();
    tree *T2 = create();
    tree *T3 = create();    
    make_tree(T1, s1);
    make_tree(T2, s2);
    sum_tree(T1->root, T2->root, T3->root); 
    print_tree(T3->root);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] next_button = new int[N];
            bool[] light = new bool[N];

            for (int i = 0; i < N; i++)
            {
                next_button[i] = int.Parse(Console.ReadLine());
                light[i] = false;
            }

            light[0] = true;

            int prev = 1;
            int next = next_button[prev - 1];
            int count = 0;

            while (!light[1])
            {
                if (light[next - 1])
                {
                    Console.WriteLine("-1");
                    return;
                }
                light[next - 1] = true;
                prev = next_button[prev - 1];
                next = next_button[next - 1];
                count++;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 15456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rt register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rt it = f; it <= e; ++it)
#define per(it, f, e) for (rt it = f; it >= e; --it)
const int MAXN = 2e5 + 10;
array<int,MAXN> h;
array<ll,MAXN> dp;
deque<int> que;
inline double slope(int j, int k) {
	return double((dp[j] + h[j] * 1ll * h[j]) - (dp[k] + h[k] * 1ll * h[k])) / (2ll * h[j] - 2ll * h[k]);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	ll n, m;
	cin >> n >> m;
	rep (i, 1, n) {
		cin >> h[i];
	}
	que.push_front(1);
	rep (i, 2, n) {
		while (que.size() > 1 && slope(que[0], que[1]) <= h[i]) {
			que.pop_front();
		}	int hd = que[0];
		dp[i] = dp[hd] + (h[i] - h[hd]) * 1ll * (h[i] - h[hd]) + m;
		while (que.size() > 1 && slope(que[que.size() - 2], que.back()) >= slope(que.back(), i)) {
			que.pop_back();
		}	que.push_back(i);
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3200
//  a u t h o r      l a l i t   k u m a r
//  
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 

int main()
{ ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
int n;
cin>>n;
int cnt=0;
ll a[n];
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
	for(int j=i+1;j<n;j++)
	{   
	    if(a[i]==a[j]) continue;
		for(int k=j+1;k<n;k++)
		{
		//	if(k!=j)
			if(a[k]==a[j]) continue;
			if(a[i]+a[j]>a[k]) cnt++;
			
		}
	}
	}

cout<<cnt<<endl;
    
}




Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>

int main(){
  long x;
  int cmp;
  int min=1000;
  scanf("%ld",&x);
  while(x>99){
    cmp = x % 1000;
    if (min > abs(cmp -753))
      min = abs(cmp -753);
    x = x/10;
  }
  printf("%d\n",min);
  return 0;
}


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

int main() {
  int N, A, B; cin >> N >> A >> B; B--;
  int ans = 0;
  for(int i = 0; i < N; i++) {
    int t; cin >> t;
    if(A <= t && t <= B) ans++;
  }
  cout << N-ans << endl;
  return 0;
}


Measured memory_bytes: 256