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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2, -1));

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j] == '#') {
        if (s[i - 1][j] != '#' && s[i + 1][j] != '#' && s[i][j - 1] != '#' &&
            s[i][j + 1] != '#') {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll slide(vector<ll>& v, ll a, ll b) {
	ll azv = abs(v[0] - a);
	ll bzv = abs(v[0] - b);
	ll aov = abs(v[1] - a);
	ll bov = abs(v[1] - b);
	v[0] = a;
	v[1] = b;
	return max((azv + bov), (bzv + aov));
}


void solv() {

	ll n, h;
	cin >> n >> h;

	priority_queue<pair<ll, ll>> q;

	for (size_t i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		q.push(pair<ll, ll>(a, 0));
		q.push(pair<ll, ll>(b, 1));
	}

	ll th = h;

	ll res = 0;
	while (th > 0)
	{
		pair<ll, ll> p = q.top();
		if (p.second == 1) {
			q.pop();
			th -= p.first;
			res++;
		}
		else {
			ll count = (th / p.first);
			th -= count * p.first;
			if (th > 0) {
				res++;
				th = 0;
			}
			res += count;
		}

	}
	cout << res << endl;
}


int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 6512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1000000 + 10;
const int mod = 1000000007;
LL a[maxn], b[maxn];
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    IOS
    int n;
    LL suma = 0, sumb = 0;
    cin >> n;
    for(int i = 1;i<=n;i++) cin >>a[i], suma+=a[i];
    for(int i = 1;i<=n;i++) cin >>b[i], sumb+=b[i];

    LL preadd = sumb - suma;
    if(preadd<0){
        cout << "No" << endl;
        return 0;
    }else{
        LL cnt = 0;
        for(int i = 1;i<=n;i++){
            if(a[i] < b[i]){
                cnt += (b[i]-a[i]+1)/2;
            }
        }
        if(cnt>preadd){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Text;

class Menagerie
{
	static int N;
	static string s;

	static public void Main(string[] args)
	{

		N = int.Parse(Console.ReadLine());
		s = Console.ReadLine();

		StringBuilder sb = new StringBuilder(N);
		sb.Append('S', N);

		sb[0] = 'S';
		sb[1] = 'S';
		if(check(sb, 2))
		{
			Console.WriteLine(sb);
			return;
		}
		sb[0] = 'S';
		sb[1] = 'W';
		if(check(sb, 2))
		{
			Console.WriteLine(sb);
			return;
		}
		sb[0] = 'W';
		sb[1] = 'W';
		if(check(sb, 2))
		{
			Console.WriteLine(sb);
			return;
		}
		sb[0] = 'W';
		sb[1] = 'S';
		if(check(sb, 2))
		{
			Console.WriteLine(sb);
			return;
		}
		Console.WriteLine(-1);
	}


	static private bool check(StringBuilder sb, int i)
	{
		if(i < N)
		{
			if(sb[i-1] == 'S')
			{
				if(s[i-1] == 'o')
				{
					sb[i] = sb[i-2];
				}
				else
				{
					if(sb[i-2] == 'S')
						sb[i] = 'W';
					else
						sb[i] = 'S';
				}
			}
			else
			{
				if(s[i-1] == 'o')
				{
					if(sb[i-2] == 'S')
						sb[i] = 'W';
					else
						sb[i] = 'S';
				}
				else
				{
					sb[i] = sb[i-2];
				}
			}
			return check(sb, i+1);
		}
		else if(i == N)
		{
			if(sb[N-1] == 'S')
			{
				if(s[N-1] == 'o')
				{
					if(sb[N-2] != sb[0])
					{
						return false;
					}
				}
				else
				{
					if(sb[N-2] == sb[0])
					{
						return false;
					}
				}
			}
			else
			{
				if(s[N-1] == 'o')
				{
					if(sb[N-2] == sb[0])
					{
						return false;
					}
				}
				else
				{
					if(sb[N-2] != sb[0])
					{
						return false;
					}
				}
			}
			return check(sb, i+1);
		}
		else
		{
			if(sb[0] == 'S')
			{
				if(s[0] == 'o')
				{
					return (sb[1] == sb[N-1]);
				}
				else
				{
					return (sb[1] != sb[N-1]);
				}
			}
			else
			{
				if(s[0] == 'o')
				{
					return (sb[1] != sb[N-1]);
				}
				else
				{
					return (sb[1] == sb[N-1]);
				}
			}
		}

	}
}


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

int main()
{
    long long n,i,j,k,q,p,b;
    cin>>n;
    long long sum=0;
    long long freq[100005];
    memset(freq, 0, sizeof(freq));
    long long  a[n];
    for(i=0;i<n;i++)
        {cin>>a[i];
            sum+=a[i];
            freq[a[i]]++;
        }
    cin>>q;
    while(q--)
    {
        cin>>p>>b;
        if(freq[p]>0)
        {
            sum-=(p*freq[p]);

            freq[b]+=freq[p];
            sum+=(b*freq[p]);
            freq[p]=0;
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 5192
#include <iostream>
#include <assert.h>
#include <vector>

#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <climits>

#define N 4
#define N2 16

using namespace std;

// const int N = 4;
// const int N2 = 16;

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'}; 


struct Node
{
	int puzzle[N2];
	int space;
	int md;
};

class Npuzzle
{
private:
	Node s_node;
	int limit;
	int md[N2][N2];
	// vector<int> path;
	int ans;
public:
	Npuzzle() {
		s_node = Node();
		int in[N2];
		for (int i = 0; i < N2; ++i)
		{
			int tmp;
			cin >> tmp;
			if(tmp == 0) {
				tmp = N2;
				s_node.space = i;
			}
			s_node.puzzle[i] = tmp;
		}
		set_md();
		s_node.md = get_md_sum(s_node.puzzle);
	}

	int get_md_sum(int *puzzle) {
		int sum = 0;
		for (int i = 0; i < N2; ++i)
		{
			if(puzzle[i] == N2) continue;
			sum += md[i][puzzle[i]-1];
		}
		return sum;
	}

	void set_md() {
		for (int i = 0; i < N2; ++i)
		{
			for (int j = 0; j < N2; ++j)
			{
				md[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
			}
		}
	}

	bool dfs(Node cur_n, int depth, int pre) {
		if(cur_n.md == 0 ) {
			ans = depth;
			return true;
		}
		if(depth + cur_n.md > limit) return false;
		int s_x = cur_n.space / N;
		int s_y = cur_n.space % N;
		for (int i = 0; i < 4; ++i)
		{
			Node new_n = cur_n;
			int new_x = s_x + dx[i];
			int new_y = s_y + dy[i];
			if(new_x < 0  || new_y < 0 || new_x >= N || new_y >= N) continue; 
			if(max(pre, i) - min(pre, i) == 2) continue;

			new_n.md -= md[new_x * N + new_y][new_n.puzzle[new_x * N + new_y] - 1];
			new_n.md += md[s_x * N + s_y][new_n.puzzle[new_x * N + new_y] - 1];
			swap(new_n.puzzle[new_x * N + new_y], new_n.puzzle[s_x * N + s_y]);
			new_n.space = new_x * N + new_y;
			// assert(get_md_sum(new_n.puzzle) == new_n.md);
			// return dfs(new_n, depth+1, i);
			if(dfs(new_n, depth + 1, i)){
				// path[depth] = i;
				return true;
			}
		}
		return false;
	}

	void ida_star() {
		for (limit = s_node.md; limit < 1000; ++limit)
		{
			// path.resize(limit);
			if(dfs(s_node, 0, -10)) {
				cout << limit << endl;
				// string str = "";
				// for (int i = 0; i < limit; ++i)
				// {
				// 	str += dir[path[i]];
				// }
				// cout << str << endl;
				return;
			}
		}
	}

	void exec() {
		ida_star();
	}
};


int main() {
	Npuzzle np = Npuzzle();
	np.exec(); 
}

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

int main() {
	long a, b, c, n, x, y;
	cin >> n;
	if(n <= 111){
		cout << 111 << endl;
		return 0;
	}else if(n <= 222){
		cout << 222 << endl;
		return 0;
	}else if(n <= 333){
		cout << 333 << endl;
		return 0;
	}else if(n <= 444){
		cout << 444 << endl;
		return 0;
	}else if(n <= 555){
		cout << 555<< endl;
		return 0;
	}else if(n <= 666){
		cout << 666 << endl;
		return 0;
	}else if(n <= 777){
		cout << 777 << endl;
		return 0;
	}else if(n <= 888){
		cout << 888 << endl;
		return 0;
	}else if(n <= 999){
		cout << 999 << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=305;
int f[N][N][N],n,K;char s[N];
int main(){
 // freopen("input.txt","r",stdin);
  scanf("%s%d",s+1,&K);n=strlen(s+1);
  for(int i=1;i<=n;i++)
      for(int k=0;k<=K;k++)f[i][i][k]=1;
  for(int len=2;len<=n;len++){
      for(int i=1;i+len-1<=n;i++){
          int j=i+len-1;
          for(int k=0;k<=K;k++){
              f[i][j][k]=max(f[i+1][j][k],f[i][j-1][k]);
              if(s[i]==s[j])f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k]+2);
              if(k)f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-1]+2);
          }
      }
  }
  cout<<f[1][n][K]<<endl;
  return 0;
}

Measured memory_bytes: 110464
while 1:
  H, W=map(int, raw_input().split())
  if H==0 and W==0:
    break
  for i in range(H):
    L=list("#"*W)
    if i%2==0:
      for j in range(W):
        if j%2!=0:
          L[j]="."
      s="".join(L)
      print s
    else:
      for j in range(W):
        if j%2==0:
          L[j]="."
        s="".join(L)
      print s
  print ""

Measured memory_bytes: 6372
#include <bits/stdc++.h>
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define int ll
const bool debug = 0;
using pii = pair<int, int>;
typedef long double D;

int32_t main()
{
    usecppio
    int n, m; cin >> n >> m;
    if (n%2==1)
    {
        for (int i = 1; i<=m; i++)
            cout << i << ' ' << n-i << '\n';
    }
    else
    {
        int odd = (m+1)/2;
        for (int i = 1; i<=odd; i++)
            cout << i << ' ' << n-i+1 << '\n';
        for (int i = odd+1; i<=m; i++)
            cout << i << ' ' << n-i << '\n';
    }
}


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

#define vi vector<int>
#define rep(i, n) for (int i = 0; i < n; i++)

int main () {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 0;
    vi d(n), v(n);
    vi ma(m);
    rep (i, n) {
      cin >> d[i] >> v[i];
      d[i]--;
      ma[d[i]] = max(ma[d[i]], v[i]);
    }
    int sum = 0;
    rep (i, m) {
      sum += ma[i];
    }
    cout << sum << endl;
    
  }
}



Measured memory_bytes: 3092
/**
 *      purpose : ABC 117 A
 *      author  : kyomukyomupurin
 *      created : 
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    double t, x; cin >> t >> x;
    cout << setprecision(15) << t / x << '\n';
    
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> {- foldl' (\acc p -> uwrite p n acc) elems path `seq`-}n
    n -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF uf@(UnionFind (_, sizes)) i = uread (findUF uf i) sizes

unionUF :: UnionFind -> Int -> Int -> UnionFind
unionUF uf@(UnionFind (elem, sizes)) i j =
  let pi  = findUF uf i
      pj  = findUF uf j
      si  = uread pi sizes
      sj  = uread pj sizes
      sij = si + sj
  in  if pi == pj
        then uf
        else
          let (t1, t2) = if si < sj then (pi, pj) else (pj, pi)
          in  UnionFind (uwrite t1 t2 elem, uwrite t1 0 $ uwrite t2 sij sizes)

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = VU.init $ ufreeze $ (\(_, _, _, acc) -> acc) $ VU.foldr'
  go
  ( group
  , m - 1
  , nC2
  , uwrite m nC2 $ accursedUnutterablePerformIO $ VUM.unsafeNew (m + 1)
  )
  abs
 where
  go (a, b) (uf, k, prev, acc) =
    let ga  = findUF uf a
        gb  = findUF uf b
        n1  = sizeUF uf a
        n2  = sizeUF uf b
        res = prev - n1 * n2
    in  ( unionUF uf a b
        , k - 1
        , if ga == gb then prev else res
        , uwrite k prev acc
        )

  nC2 = n * (n - 1) `div` 2

  group :: UnionFind
  group = UnionFind
    (uthaw $ VU.enumFromN 0 n, accursedUnutterablePerformIO $ VUM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nm  <- VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    (nm VU.! 1)
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  VU.mapM_ print $ solve (nm VU.! 0) (nm VU.! 1) abs


Measured memory_bytes: 35196
#include <iostream>
#include <iomanip>
/*cout<<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示かつゼロ埋め無*/
/*cout<<fixed<<setprecision(11)<<ret<<endlで、小数部のみ11桁表示かつゼロ埋め有*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
/*int main(void){
    int x;cin>>x;
    int a=-1;
    rep(i,4){
        int tmp=x%10;
        if(a==tmp){
            cout<<"Bad"<<endl;
            return 0;
        }else{
            a=tmp;
            x/=10;
        }
    }
    cout<<"Good"<<endl;

    return 0;
}*/
//////////////////
//  B
/*int main(void){
    int n,l;cin>>n>>l;
    int Left=l,Right=l+n-1;

    int eat;
    if(Left>=0)eat=Left;
    else if(0>=Right)eat=Right;
    else eat=0;

    int sum=n*(l-1) + n*(n+1)/2;//tigau

    cout<<(sum-eat)<<endl;
    return 0;
}*/
//////////////////
//  C //解説を見たら実装できた
/*long long gcd(long long a, long long b){//最大公倍数を求める
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}
long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}
int main(void){
    long long a,b,c,d;cin>>a>>b>>c>>d;

    long long l=lcm(c,d);//最小公倍数
    long long b_ret = b - b/c - b/d + b/l;//b以下の整数のうち、cでもdでもわれないものの個数
    a=a-1;
    long long a_ret = a - a/c - a/d + a/l;

    cout<<b_ret-a_ret<<endl;
    return 0;
}*/
//////////////////
//  D　
int main(void){
    int n;cin>>n;
    vector<pair<int,int> > v(n);
    
    rep(i,n){
        cin>>v[i].second>>v[i].first;
    }
    sort(v.begin(),v.end());

    long long suma=0;
    rep(i,n){
        suma+=v[i].second;
        if(suma>v[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 4800
N=int(input())
A=[int(_) for _ in input().split(" ")]

A.sort(reverse=True)

#print(A)

ans=0
ans+=A[0]

if len(A)%2==1:
  for i in range(1,N-1):
    ans+=A[(i+1)//2]
    #print("ans",ans)
else:
  for i in range(1,N-1):
    ans+=A[(i+1)//2]
    #print("ans",ans)

print(ans)


Measured memory_bytes: 31412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
int n,p[5003],len;
int K;
ll C[5002],ans=-INF,ret[5002];
void dfs(int x,int w){
    if(x==w)return;
    ++len;
    ret[len]=ret[len-1]+C[p[x]];
    dfs(p[x],w);
}
int main(){
    cin>>n>>K;
    for(int i=1;i<=n;i++)cin>>p[i];
    for(int i=1;i<=n;i++)cin>>C[i],ans=max(ans,C[i]);
    for(int i=1;i<=n;i++){
        ret[1]=C[p[i]];
        len=1;
        dfs(p[i],i);
        for(int j=1;j<=min(len,K);j++)ans=max(ans,ret[j]);
        if(K>len&&ret[len]>0){
            ll pr=K/len,ps=K%len,res=pr*ret[len];
            for(int j=0;j<=ps;j++)ans=max(ans,res+ret[j]);
            for(int j=0;j<=len;j++)ans=max(ans,res-ret[len]+ret[j]);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3692
num = int(input())
A = input().split(" ")
B = A.copy()

#bubble sort
for i in range(num):
	for j in range(num-1,i,-1):
		#英字ではなく、数字で比較する
		m1 = int(A[j][1:])
		m2 = int(A[j-1][1:])
		if m1 < m2:
			A[j],A[j-1] = A[j-1],A[j]

print(*A)
print("Stable")

#selection sort
for i in range(num):
	minv = i
	for j in range(i+1,num):
		m1 = int(B[minv][1:])
		m2 = int(B[j][1:])
		if m1 > m2:
			minv = j
	B[i],B[minv] = B[minv],B[i]

print(*B)
if A == B:
	print("Stable")
else:
	print("Not stable")




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

int t[86401];

int convert(int h,int m,int s){
  
  int sec=0;
  
  sec=s+(m*60)+(h*3600);
  
  return sec;
}
int main(){
  
  int n;
  int h,m,s;
  char dum;

  while(1){

    cin >>n;
    if(n==0)break;

    for(int i=0 ; i < 86401 ; i++)t[i]=0;
    
    int cnt=1;
    
    for(int i=0 ; i < n ; i++){
      cin >>h>>dum>>m>>dum>>s;
      int S=convert(h,m,s);
      cin >>h>>dum>>m>>dum>>s;
      int G=convert(h,m,s);
      bool flag=false;
      for(int j=S ; j < G ; j++){
	t[j]++;
	if(t[j] > cnt)flag=true;
      }
      if(flag)cnt++;
    }
    
    cout <<cnt<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1496
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>
bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}




int main(){
    int n; cin >> n;
    string s; cin >> s ;
    int ans = n + 1;
    VI white(n, 0);
    white[0] = (s[0] == '.');
    FOR(i, 1, n)
        white[i] = white[i-1] + (s[i] == '.');
    REPS(i, n){ //i-1文字目まで黒く、i文字目以降白く (0-ordered)
        int cnt = 0;
        if(i > 0) cnt += i - white[i-1];
        if(i < n) cnt += white[n-1] - white[i];
        chmin(ans, cnt);
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
	int N, M, X, Y, x_max, y_min;
	cin >> N >> M >> X >> Y;
	x_max = X, y_min = Y;
	int *x=new int[N], *y=new int[M];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		if (x_max < x[i])
			x_max = x[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> y[i];
		if (y_min >= y[i])
			y_min = y[i];
	}
	if (x_max < y_min)
		cout << "No ";
	cout << "War\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	//static Map<Long,Long>map=new TreeMap<>();
	static String ans="";
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       String a=sc.next();
       String b=sc.next();
          if(a.length()>b.length())ans="GREATER";
          if(a.length()<b.length())ans="LESS";
          if(a.length()==b.length()) {
        	  ans="EQUAL";
        	  for(int i=0;i<a.length();i++) {
        		  if(Integer.parseInt(a.substring(i, i+1))>Integer.parseInt(b.substring(i, i+1))){
        			  ans="GREATER";
        			  break;
        		  }
        		  else if(Integer.parseInt(a.substring(i, i+1))<Integer.parseInt(b.substring(i, i+1))){
        			  ans="LESS";
        			  break;
        		  }
        	  }
          }
       System.out.println(ans);
    }
}

Measured memory_bytes: 25300
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = float('inf')
for i in range(N-K+1):
    a = abs(A[i] - A[i+K-1])
    ans = min(ans, abs(A[i])+a, abs(A[i+K-1])+a)
print(ans)

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

int main(){
    int a,b;
    cin >> a >> b;
    string ans;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible";
    else cout << "Impossible" << endl;
}


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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

int cnt[NAX];
class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (auto &x : a)
        {
            cin >> x;
            cnt[x]++;
        }
        int q;
        cin >> q;
        ll res = accumulate(all(a), 0LL);
        while (q--)
        {
            int b, c;
            cin >> b >> c;
            res += cnt[b] * (0LL + c - b);
            cnt[c] += cnt[b];
            cnt[b] = 0;
            cout << res << '\n';
        }
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

vector<pair<ll, ll>> v;
void f(ll n) {
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;
        ll ex = 0;
        while(n % i == 0) {
            ex++;
            n /= i;
        }
        v.push_back({i, ex});
    }
    if(n != 1) v.push_back({n, 1});
    return;
}

int main() {
    ll n, p;
    cin >> n >> p;

    f(p);

    ll ans = 1;
    for(auto q : v) {
        rep(i, q.second / n) ans *= q.first;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int n; cin >> n;
  int k; cin >> k;
  int q; cin >> q;
  vector<int> arr(n);
  int tmp;
  for (int i = 0; i < q; i++) {
    cin >> tmp;
    arr.at(tmp-1) += 1;
  }

  for (int i = 0; i < n; i++) {
    if (q-arr.at(i) >= k) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll m=1000000007;
vector<vector<ll>> multiply(vector<vector<ll>> a,vector<vector<ll>> b)
{
    int n=a.size();
    vector<vector<ll>> res(n,vector<ll>(n,0));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int x=0;x<n;x++)
            {
                res[i][j]+=a[i][x]*b[x][j];
                res[i][j]=res[i][j]%m;
            }
        }
    }
    return res;
}
vector<vector<ll>> power(vector<vector<ll>> adj,ll k)
{
    if(k==1)
    {
        return adj;
    }
    vector<vector<ll>> res=power(adj,k/2);
    if(k%2==0)
    {
        return multiply(res,res);
    }
    else
    {
        return multiply(multiply(res,res),adj);
    }
}
ll solve(vector<vector<ll>> adj,ll k,ll n)
{
    vector<vector<ll>> res=power(adj,k);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            ans+=res[i][j];
            ans=ans%m;
        }
    }
    return ans;
}
int main() {
	ll n,k;
	cin>>n>>k;
	vector<vector<ll>> adj(n,vector<ll>(n));
	for(int i=0;i<n;i++)
	{
	    for(int j=0;j<n;j++)
	    {
	        cin>>adj[i][j];
	    }
	}
	ll ans=solve(adj,k,n);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4940
#include <iostream>

using namespace std;

int main()
{
     string s;
     int ans=0;
     cin>>s;
     for(int i =0 ;i<s.size();i++)
     {
         if(s[i]=='-')
            ans--;
         else
            ans++;
     }
    cout<<ans;

	return 0;

}


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

int main(void){
    int n,k,s = 0,a[50],b[50],c[50];
    int i;
    scanf("%d",&n);
    
    for (i = 0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for (i = 0; i<n; i++){
        scanf("%d", &b[i]);
    }
    for (i = 0; i<n-1; i++){
        scanf("%d", &c[i]);
    }
    for (i = 0; i<n; i++){
        k=a[i]-1;
        s=b[k]+s;
        if(a[i]>0){
            if((a[i]-1)==a[i-1]){
                s=s+c[k-1];
            }
        
        }
        
    }
    
    printf("%d",s);
    return 0;
}



Measured memory_bytes: 128
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    float d,t,s;
    cin>>d>>t>>s;
    float ha= d/s;
    if(ha <= t) cout<<"Yes";
    else cout<<"No";
}

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

int n;
int a[100101];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  for(int i=0;i<100101;i++)a[i]=0;
  for(int i=0;i<n;i++){
    int b;cin>>b;
    b++;
    a[b]++;
    a[b-1]++;
    a[b+1]++;
  }
  int ans=0;
  for(int i=0;i<100101;i++){
    if(ans<a[i]){
      ans=a[i];
    }
  }
  cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 640
#coding=UTF-8
#単純にやっていったら間に合わないよ

hou=10**9+7
mozir=input()
hyo=mozir.split(' ')
n=int(hyo[0])
m=int(hyo[1])

mozir=input()
hyo=mozir.split(' ')
TateLine=[ int(mono) for mono in hyo]


mozir=input()
hyo=mozir.split(' ')
YokoLine=[ int(mono) for mono in hyo]

#滅茶苦茶積を足す
TateYoso=0
for idx in range(0,n-1,1):
    TateYoso+= (n-(idx+1)) * (TateLine[n-(idx+1)]-TateLine[idx])
    TateYoso%= hou

YokoYoso=0
for idy in range(0,m-1,1):
    YokoYoso+= (m-(idy+1)) * (YokoLine[m-(idy+1)]-YokoLine[idy])
    YokoYoso%= hou

ans=(TateYoso*YokoYoso)%hou
print(ans)


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

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

  ll H1, M1; cin >> H1 >> M1;
  ll H2, M2; cin >> H2 >> M2;
  ll K; cin >> K;

  ll s = H1 * 60 + M1;
  ll e = H2 * 60 + M2;

  ll ans = (e - s - K);
  cout << ans << '\n';
  return 0;
}

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

int main() {
  string S;
  cin >> S;

  vector<string> devide = {"maerd", "remaerd", "esare", "resare"};

  reverse(S.begin(), S.end());

  int i = 0;
  bool can = true;
  while (i < S.size() && can == true) {
    bool can2 = false;
    for (int j = 0; j < 4; j++) {
      string d = devide.at(j);
      if (S.substr(i, d.size()) == d) {
        can2 = true;
        i += d.size();
        break;
      }
    }
    if (can2 == false) {
      can = false;
    }
  }

  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int a[111111], b[111111];
int main() {
    int p, q, m, A = 1e9, B = 1e9;
    cin >> p >> q >> m;
    for(int i = 0; i < p; i++)
        cin >> a[i], A = min(A, a[i]);
    for(int i = 0; i < q; i++)
        cin >> b[i], B = min(B, b[i]);
    int r = A + B;
    for(int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        r = min(r, a[x - 1] + b[y - 1] - c);
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef vector<int>Vl;
typedef vector<vector<int>>Vv;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=1e5+2;
const int inf=(int)(1e19+10LL);
const int mod=1e9+7;
#define PI 3.14159265358979323846264338327950L
Vl graph[Nx];
int n,m;
map<int,int>freq;
bool visited[Nx];
void dfs(int src){
//	cout<<src<<endl;
	visited[src]=true;
	for(auto it:graph[src]){
		if(visited[it])continue;
		dfs(it);
	}
}
void bfs(){
	queue<int>q;
	q.push(1);
	bool vis[n+1];
	ms(vis,false);
	vis[1]=true;
	while(!q.empty()){
		int frnt=q.front();
		q.pop();
		for(auto it:graph[frnt]){
			if(vis[it])continue;
			vis[it]=true;
			freq[it]=frnt;
			q.push(it);
		}
	}
}
void solve(){
	sl(n);sl(m);
	//graph=vector<vector<int>>(n+1);
	for(int i=1;i<=m;i++){
		int u,v;
		sl(u);sl(v);
		graph[u].pb(v);
		graph[v].pb(u);
	}
	ms(visited,false);
	dfs(1);
	for(int i=1;i<=n;i++){
		if(!visited[i]){
		//	cout<<i<<" "<<endl;
	       cout<<"No"<<endl;
		  return;
			
		}
	}
	cout<<"Yes"<<endl;
    bfs();
    for(auto it:freq){
    	cout<<it.S<<endl;
    }
}

signed main(){
  int test=1;
  //sl(test);
  int t=0;
 while(t++<test){
 //	cout<<"Case #"<<t<<": ";
 	solve();
 }
 
}

Measured memory_bytes: 16824
import java.util.Hashtable;
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Hashtable<Character,Integer> roman = new Hashtable<Character,Integer>();
		roman.put('I',1);
		roman.put('V',5);
		roman.put('X',10);
		roman.put('L',50);
		roman.put('C',100);
		roman.put('D',500);
		roman.put('M',1000);
		while(sc.hasNext()){
			char[] s = sc.nextLine().toCharArray();
			int ans = 0;
			for(int i=0;i<s.length-1;i++){
				if(roman.get(s[i]) >= roman.get(s[i+1])) ans += roman.get(s[i]);
				else ans -= roman.get(s[i]);
			}
			ans += roman.get(s[s.length - 1]);
			System.out.println(ans);
		}
	}
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define rep_cs(i, l, n) for (int i = (l); i <= (n); i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

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

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vll a(M);
    rep(i, 0, M) cin >> a[i];

    ll sum = 0;
    rep(i, 0, M) sum += a[i];

    if (N - sum >= 0)
    {
        cout << N - sum << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3672
import java.lang.Math.*
import java.util.*

fun solvePaintingBallsWithAtcodeer(){
    val sc = Scanner(System.`in`)
    val node = sc.nextInt()
    val k = sc.nextInt()
    val ans = pow((k-1).toDouble(),(node-1).toDouble()).toInt() * k

    println(ans)
}

fun main(args: Array<String>){
    solvePaintingBallsWithAtcodeer()
}

Measured memory_bytes: 29468
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <vector>

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

    int32_t A,B;
    std::cin >> A >> B;


    int32_t res;
    if(A < 10 && B < 10){
        res = A * B;
    }
    else{
        res = -1;
    }

    std::cout << res;

    return 0;
}


Measured memory_bytes: 256
/* Made by Takauov Yerzhan - 31/01/2020 */
#include <bits/stdc++.h>
#define enter endl
#define LL long long
#define LD long double
#define UL unsigned long long
#define Okoshka ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define F first
#define S second

using namespace std;

const LL MXN = 3e5 + 7;
const LL MOD = 1e9 + 7;
const LL INF = 1e18 + 7;

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

int n, a[MXN], sum, x;

int main()
{
    ///Okoshka;
    cin >> x >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    if(sum >= x) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 640
import java.util.Scanner

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    var N = sc.nextInt()
    val K = sc.nextInt()

    val max = N - K + 1
    val min = if(K > 1){
        1
    }else{
        N
    }
    println(max - min);
}

Measured memory_bytes: 31384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
int t[111][111];

int cnt(int x){
		int ret=0;
		FOR(i,0,x+1)ret+=t[0][i];
		FOR(i,x,n)ret+=t[1][i];
		return ret;
}

int main() {
		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
		cin>>n;
		FOR(i,0,n)cin>>t[0][i];
		FOR(i,0,n)cin>>t[1][i];
		int ans =0;
		FOR(i,0,n){
				ans=max(ans,cnt(i));
		}
		cout<<ans<<endl;






		return 0;
}


Measured memory_bytes: 896
def main():
	import numpy as np
	min = -1
	s = input()
	n = len(s)
	for i in range(n-2):
		buf = int(s[i:i+3])
		bufmin = np.abs(buf-753)
		if(min == -1):
			min = bufmin
		else:
			if(bufmin < min):
				min = bufmin
	print(min)

main()# your code goes here

Measured memory_bytes: 20752
a,b = map(int, input().split())
if a == 1:
    if b == 1:
        print("Draw")
    else:
        print("Alice")
else:
    if a == b:
        print("Draw")
    elif b == 1:
        print("Bob")
    elif a > b:
        print("Alice")
    else:
        print("Bob")

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

int n;
double p[3005];
double dp[3005][3005];
// row = number of tosses
//coloum = number of times when it came heads
int main() {
   
    cin >> n;
    for(int i =1; i <= n;i++) cin >> p[i];
    dp[1][0] = (1.0 - p[1]);
    for(int i = 2; i <= n; i++) {
        dp[i][0] = dp[i-1][0] *(1.0 - p[i]); 
    }
    dp[1][1] = p[1];
    for(int i=2; i<= n; i++) {
        dp[i][i]= dp[i-1][i-1]* p[i];
    }
    for(int i = 1;  i <= n; i++) {
        for(int j = 1; j < i; j++) {
            dp[i][j] = dp[i-1][j] * (1.0 - p[i]) +  dp[i-1][j-1] * p[i];
        }
    }
    double ans = 0.0;
    for(int i = n/2 + 1; i <= n;  i++) {
        ans += dp[n][i];
    }
    printf("%0.10lf", ans);
	return 0;
}

Measured memory_bytes: 68992
x = int(input())
if x<600:
    print(8)
elif x<800:
    print(7)
elif x<1000:
    print(6)
elif x<1200:
    print(5)
elif x<1400:
    print(4)
elif x<1600:
    print(3)
elif x<1800:
    print(2)
else:
    print(1)

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b,x,upper,temp,jougen;
    cin >> x;
    jougen = 1000000001;
    temp = 0;
    upper = 1;
    while(temp < jougen){
        temp = upper * upper * upper * upper * upper - (upper-1) * (upper-1) * (upper-1) * (upper-1) * (upper-1);
        upper += 1;
    }
    //upper = (ll)pow(2*x,0.2);
    for(ll i = upper; i > 0; i--){
        if(i * i * i * i * i - x < 0){
            temp = -(ll)pow(x - i * i * i * i * i  ,0.2);
        }
        else if(i * i * i * i * i - x  > 0){
            temp = (ll)pow( i * i * i * i * i - x ,0.2);
        }
        else if(i * i * i * i * i - x == 0){
            temp = 0;
        }
        if (i * i * i * i * i - temp * temp * temp * temp * temp == x){
            a = i;
            b = temp;
            break;
        }
    }
    cout << a << ' '<< b << endl;

    
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int sum=0;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	int mi=a[0];
	for(int i=0;i<n;i++)
	{
		if(a[i]<=mi)
		{
			sum++;
			mi=a[i];
		}
	}
	cout<<sum;
} 

Measured memory_bytes: 1024
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll bcnt(VV<char> & v){
  ll ret=0;
  rep(i,0,siz(v)){
    rep(j,0,siz(v[0])){
      if(v[i][j]=='#')++ret;
    }
  }
  return ret;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,w,k,ans=0;cin>>h>>w>>k;


  VV<char> v(h,V<char>(w)),tmp=v;

  rep(i,0,h)rep(j,0,w)cin>>v[i][j];


  rep(i,0,1<<h){
    rep(j,0,1<<w){
      tmp=v;
      rep(g,0,h){
        rep(r,0,w){
          if((i&(1<<g))||(j&(1<<r)))tmp[g][r]='R';
        }
      }

      if(bcnt(tmp)==k){
        ans++;
      }
    }
  }

  cout<<ans<<ENDL;
  
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3644
import numpy as np
N, M = map(int, input().split())

store = {}
for i in range(N):
    a, b = map(int, input().split())
    if a in store: store[a] += b
    else: store[a] = b
key = list(store.keys())
key.sort()

bins = 0
total = 0
for k in key:
    if bins + store[k] < M:
        bins += store[k]
        total += k * store[k]
    else:
        total += k * (M-bins)
        break
print(total)

Measured memory_bytes: 26856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int n , AC = 0 , WA = 0 , TLE = 0 , RE = 0;
    cin >> n;
    vector <string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(s[i] == "AC"){
            AC++;
        }
        if(s[i] == "WA"){
            WA++;
        }
        if(s[i] == "TLE"){
            TLE++;
        }
        if(s[i] == "RE"){
            RE++;
        }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}

Measured memory_bytes: 6364