akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    static int M = 998244353;

    public static void main(String[] args) {
        int N = in.i();
        int[] a = new int[N];
        int max = 0;
        long ans = in.i() == 0 ? 1 : 0;
        a[0]++;
        for (int i = 1; i < N; i++) {
            int d = in.i();
            if (max < d) max = d;
            a[d]++;
        }
        ans = a[0] == 1 ? ans : 0;
        int v = 1;
        for (int i = 1; i <= max; i++) {
            ans = ans * pow(v, a[i]) % M;
            v = a[i];
        }
        out.println(ans);
    }

    static long pow(long a, int b) {
        long c = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                c = c * a % M;
            }
            a = a * a % M;
            b >>= 1;
        }
        return c;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 35900
N, K, S = map(int, input().split())
MAX = 10 ** 9
if K == 0:
    if S == MAX:
        print(' '.join(['1']*N))
    else:
        print(' '.join([str(S+1)]*N))
elif K == N:
    print(' '.join([str(S)]*N))
else:
    if S == MAX:
        print(' '.join([str(S)]*K+['1']*(N-K)))
    else:
        print(' '.join([str(S)]*K+[str(MAX)]*(N-K)))

Measured memory_bytes: 6252
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
long long power(long long k , long long n , long long m=1e9+7)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}
ll nck(ll n , ll k ,ll m=1e9+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}
long long fact(long long n , long long m = 1e9+7)
{
    long long a = 1 ;
    if(n==0 || n==1)
    {
        return(1) ;
    }
    while(n>0)
    {
        a = (a%m * n%m)%m ;
        n-- ;
    }
    return(a) ;
}
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf ( std::ios::floatfield );//this and next line for floating precision upto 6
    std::cout.precision(10);
    ll a,b,c,d,e,x,i,j,n,t,m,k,y,s;
    double p,q,r,w,u ;
    string str = "",str1 = "" ;
    char ch,chr ;
    ll a1,a2,b1,b2 ;
    cin>>n ;
    vll v;
    READ(v,n);
    c = 0 ;
    for(i=0 ; i<n ;)
    {
    	if(v[i]==0)
    	{
    		i++ ;
    		continue ;
		}
        a = v[i];
        for(j=i ; j<n ; j=j+1)
        {
            if(v[j]==0)
            {
                break;
            }
            a = min(a,v[j]);
        }
        for(k=i ; k<j ; k=k+1)
        {
            v[k]-=a ;
        }
        c+=a ;
    }
    cout<<c ;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# input
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, input().split())
s = input()
range_len = 2 * k + 1
ans = 0
block_len = []
block_len.append(0)
now = "1"
for i in s:
    if now == i:
        block_len[-1] += 1
    else:
        block_len.append(1)
        now = i
if now == "0":
    block_len.append(0)
l_block = len(block_len)
# print(block_len)
if l_block <= range_len:
    print(n)
else:
    # 尺取
    tmp = sum(block_len[:range_len])
    ans = tmp
    for idx in range(l_block - range_len):
        tmp += block_len[idx + range_len] - block_len[idx]
        # print(tmp, idx)
        if idx % 2 == 1:
            # print(ans, tmp)
            ans = max(ans, tmp)

    print(ans)



Measured memory_bytes: 10496
// Example program
#include <iostream>
#include<stdio.h>
#include <string.h>
using namespace std;
int main()
{
  int n,m,col, b[1000][1000],arr[100004], nep = 0, krat = 0;
  scanf("%d %d", &n, &m);
  scanf("%d", &col);
  for(int i =0; i < col;i++){
    scanf("%d", &arr[i]);
  }
  int ind = 0;
  int k = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      arr[ind]--;
      b[i][j]=ind + 1;
      if(arr[ind]==0){
        ind++;
      }
      if(ind == col){
        break;
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(i % 2 == 0){
      cout<<b[i][j]<<" ";
      }else{
        cout<<b[i][m-j-1]<<" ";
      }
    }
    cout<<endl;
  }
}


Measured memory_bytes: 2560
# coding: utf-8
# Your code here!
import sys

n = int(input())
h = list(map(int, input().split()))
h = h[::-1]
for i in range(1, n):
  if h[i] >= h[i-1] + 2:
    print("No")
    sys.exit()
  elif h[i] == h[i-1] + 1:
    h[i] -= 1
print("Yes")    


Measured memory_bytes: 20760
using System;
class aoj
{
    static void Main()
    {
        decimal[] a = new decimal[5];
        for(int i = 0; i < 5; i++)
        {
            a[i] = decimal.Parse(Console.ReadLine());
        }
        decimal b = Math.Ceiling(a[1] / a[3]);
        decimal c = Math.Ceiling(a[2] / a[4]);
        if (b > c)
        {
            Console.WriteLine(a[0] - b);
        }
        else
        {
            Console.WriteLine(a[0] - c);
        }
    }
}

Measured memory_bytes: 9428
#include <stdio.h>

int main(){
	int a,b,c;
	int x;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&b==c){
		x = 1;
	}else if(a==b||b==c||c==a){
		x = 2;
	}else{
		x=3;
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    cout << (n+1)%2 << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<string> W(N);
  for(int i=0; i<N; i++){
    cin >> W[i];
  }
  int flag=0;
  for(int i=0; i<N-1; i++){
    if(W[i].at(W[i].size()-1)!=W[i+1].at(0)){
      flag++;
    }
  }
  sort(W.begin(), W.end());
  for(int i=0; i<N-1; i++){
    if(W[i]==W[i+1]){
      flag++;
    }
  }
  if(flag!=0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys


def main():
    a, b, c = [int(i) for i in sys.stdin.readline().split(' ')]
    divisors = 0
    for i in range(a, b+1):
        if i == 0:
            continue
        elif c % i == 0:
            divisors += 1
    print(divisors)
    return


if __name__ == '__main__':
    main()



Measured memory_bytes: 5608
using System;
// using System.Collections.Generic;
// using System.Globalization;
// using System.IO;
// using System.Linq;
// using System.Text;
// using System.Text.RegularExpressions

class Program
{
    static void Main()
    {
        string[] arr = Console.ReadLine().Split();
        int N, A, B;
        N = int.Parse(arr[0]);
        A = int.Parse(arr[1]);
        B = int.Parse(arr[2]);
        Console.WriteLine(Math.Min(A * N, B));
        return;
    }
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n, m, ans=0;
    cin >> n >> m;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<queue<ll>> g(n);

    rep(i, m) {
        ll a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push(b);
        g[b].push(a);
    }
    rep(i, n) {
        ll me = h[i]; // 自分の高さ
        bool ok = true;
        while(!g[i].empty()) {
            ll x = h[g[i].front()];
            g[i].pop();
            if(me <= x) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 71932
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	cin >> N;

	vint A(N + 1), B(N);

	for (int i = 0; i < N + 1; i++) {
		cin >> A[i];
	}

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

	int ans = 0;

	for (int i=N-1;i>=0;i--) {
		//B[i]はA[i+1]をぶった雄
		dbg(A[i+1]);
		dbg(B[i]);
		
		int tmp = min(A[i + 1], B[i]);
		A[i + 1] -= tmp;
		B[i] -= tmp;

		ans += tmp;
		
		tmp = min(A[i], B[i]);
		A[i] -= tmp;
		B[i] -= tmp;

		ans += tmp;
		
		dbg(tmp);
	}

	//ans += min(A[0], B[0]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int X, Y, A, B, C; 
  cin >> X >> Y >> A >> B >> C;

  vector<int> p(A);
  REP(i, A) cin >> p[i];

  vector<int> q(B);
  REP(i, B) cin >> q[i];

  vector<int> r(C);
  REP(i, C) cin >> r[i];

  sort(ALL(p), greater<>());
  sort(ALL(q), greater<>());
  sort(ALL(r), greater<>());

  int ans = 0;
  priority_queue<int, vector<int>, greater<int>> qa, qb;
  REP(i, X){
    qa.push(p[i]);
    ans += p[i];
  }
  REP(i, Y){
    qb.push(q[i]);
    ans += q[i];
  }

  int cnt = 0;
  while(1){
    int a = qa.top();
    int b = qb.top();

    if(min(a, b) < r[cnt]){
      if(a < b){
        qa.pop();
        qa.push(r[cnt]);
        ans += r[cnt]-a;
      }else{
        qb.pop();
        qb.push(r[cnt]);
        ans += r[cnt]-b;
      }
      cnt++;
    }else{
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

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

const int mx = 1e9+5;
int m[100005];
int T[100005];

// 10 30 40 20
// 0   1  2  3
//    10  20
int minHeightIncurred(int i , int n ,int val , int *res)
{
	if(T[i] != -1)
	{
		if(val + T[i] < *res)
			*res = val + T[i];
				
		return *res;
	}
	else
	{
		int k =0 , t =val; // preserving 
		if(i<n-1)
		{
			k = abs(m[i] - m[i+1]);
			val = minHeightIncurred(i+1 , n , val + k , res);
		}
			
		if(i<n-2)
		{
			k =  abs(m[i] - m[i+2]);
			val = t;	
			val = minHeightIncurred(i+2 , n , val + k , res);
		}
		

		// Here 'val' contains the min. val for each path
		if(*res>val)
		{
			*res =val;
		}
		else
		{
			T[i] = abs(val - t);
		}

		return *res;
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	memset(T , -1  , sizeof(T));

	int n;
	cin>>n;

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

	minHeightIncurred(0 , n , 0 , &res); // INDEX , SIZE  , JMP_VAL
	cout<<res<<"\n";
}

//END










Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N; 
vector<int> dp;
vector<vector<int>> vec;
vector<vector<int>> graph;

void dfs(int u, int p = -1){
  for(auto v : graph[u]){
    if(v == p) continue;
    dfs(v, u);
  }

  if(vec[u].size() == 0){
    dp[u] = 1;
  }else{
    sort(ALL(vec[u]));

    REP(i, vec[u].size()){
      chmax(dp[u], vec[u][i]+(int)vec[u].size()-i);
    }
  }

  if(p != -1) vec[p].emplace_back(dp[u]);
}

signed main() {
  cin >> N;

  graph.resize(N);
  REP(i, N-1){
    int v;
    cin >> v; v--;
    graph[i+1].emplace_back(v);
    graph[v].emplace_back(i+1);
  }

  vec.resize(N);
  dp.resize(N);

  dfs(0);

  cout << dp[0]-1 << "\n";

  return 0;
}

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

int main() {
  int dx[8]={1,1,1,0,0,-1,-1,-1};
  int dy[8]={1,0,-1,1,-1,1,0,-1};
  int H,W ;
  cin >> H >> W ;
  string S[H];
  for (int i=0;i<H;i++) cin >> S[i];
  for (int i=0;i<H;i++) {
    for (int j=0;j<W;j++) {
      if(S[i][j]=='.') {
        int count=0;
        for (int k=0;k<8;k++) {
          int x=i+dx[k];
          int y=j+dy[k];
          if (0<=x &&x<H &&0<=y&&y<W&&S[x][y]=='#') count++;
        }
        S[i][j]='0'+count ;
      }
    }
  }
  for (int i=0;i<H;i++) cout << S[i] <<endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, k; cin >> n >> k;
    lli cnt = 0;
    rep(i, n){
        lli h; cin >> h;
        if(h < k) cnt++;
    }
    cout << n-cnt << endl;
}

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

int main(){
  string o, e;
  cin >> o >> e;
  rep(i, o.size()){
    cout << o[i];
    if (i < e.size()) cout << e[i];
  }
      
    
}

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

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	int tmp = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')tmp++;
		else if (s[i] == 'D')tmp--;
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import collections
import numpy as np
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

motiten = [k]*n
mon_sei = [q]*n
for i in a:
    mon_sei[i-1] -= 1

ans = np.array(motiten) - np.array(mon_sei)
for i in range(len(ans)):
    if ans[i] > 0:
        print('Yes')
    else:
        print('No')

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

int main(){
    int max;
    int num1, num2;
    cin >> num1;
    cin >> num2;
    if(num1 > num2){
        max = num1;
        num1 = num1-1;
    }
    else{
        max = num2;
        num2 = num2-1;
    }
    if(num1 > num2){
        max += num1;
    }
    else{
        max += num2;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

const int MAXN = 105;
using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

struct edge{
  edge(int from,int to):from(from),to(to){}
  int from,to;
};

bool operator<(edge a,edge b){
  if(a.from != b.from)return a.from < b.from;
  else return a.to < b.to;
}

typedef pair<int,pair<int,int> > P;

int main(){
  int n,m;
  while(cin >> n >> m && (n | m) != 0){
    priority_queue<P,vector<P> ,greater<P> > que;
    for (int i = 0; i < m; ++i){
      int a,b,c;
      cin >> a >> b >> c;
      que.push(make_pair(c,make_pair(a, b)));
    }
    UnionFind u(MAXN);
    int ans = 0;
    for (int i = 0; i < m; ++i){
      int from = que.top().second.first;
      int to = que.top().second.second;
      int cost = que.top().first;
      que.pop();
      if(!u.findSet(to, from)){
	//cout << "cost:" << cost << " " << top.to << " " << top.from << endl;
	ans += cost;
	u.unionSet(to,from);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n/10==9 || n%10==9)
        cout<<"Yes";
        else
        cout<<"No";
    } 
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <unordered_map>
#include <vector>
#include <utility>
#include <algorithm>

std::pair<int, int> func(const std::pair<int, int>& v1, const std::pair<int, int>& v2)
{
    auto [l1, r1] = v1;
    auto [l2, r2] = v2;

    if (r1 > l2) {
        return {l1, r1 + r2 - l2};
    } else {
        return {l1 + l2 - r1, r2};
    }
}

int main()
{
    long N;
    std::cin >> N;

    std::vector<std::pair<long, long>> v;

    for (long i = 0; i < N; ++i) {
        long l = 0, r = 0;
        std::string s;
        std::cin >> s;
        for (auto c : s) {
            if (c == ')') {
                if (r > 0) {
                    r--;
                } else {
                    l++;
                }
            } else {
                r++;
            }
        }
        v.emplace_back(l, r);
    }

    std::sort(v.begin(), v.end(), [](const std::pair<long, long>& v1, const std::pair<long, long>& v2) {
        // return (l.first - l.second) < (r.first - r.second);
        auto [l1, r1] = func(v1, v2);
        auto [l2, r2] = func(v2, v1);

        if (l1 < l2) {
            return true;
        } else if (l2 < l1) {
            return false;
        } else {
            return r1 < r2;
        }
    });

    /*
    for (auto& w : v) {
        auto [l2, r2] = w;
        std::cout << l2 << ':' << r2 << " ";
    }
    std::cout << std::endl;
    */


    long l = 0, r = 0;
    for (auto& w : v) {

        std::tie(l, r) = func({l, r}, w);

        if (l > r) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    // std::cout << std::endl;
    // std::cout << l << ':' << r << std::endl;

    if (l == 0 && r == 0) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 19776
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
using  ll =long long;

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    char in;
    while(cin>>n>>m){
        for(int i=0;i<n;i++){
            cin>>in;
            if(i==m-1){
                cout << (char)(in+32);
            }
            else
                cout << in;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
class Module
  def tco(name)
    continue = []
    first = true
    arguments = nil

    private_name = "private_" + name.to_s
    alias_method private_name, name
    private private_name

    define_method(name) do |*args|
      if first
        first = false
        while true
          result = send(private_name, *args)
          if result.equal? continue
            args = arguments
          else
            first = true
            return result
          end
        end
      else
        arguments = args
        continue
      end
    end
  end
end


class Solve
  def parent(x)
    return x if $mark[x]
    parent($arr[x])
  end
  tco :parent
end

loop do
  n, q = gets.split.map(&:to_i)
  break if n == 0
  $arr = Array.new(n+1)
  (2..n).each{ |i| $arr[i] = gets.to_i }
  $mark = Array.new(n+1)
  $mark[1] = true

  sum = 0
  s = Solve.new
  q.times do
    cmd, n = gets.split
    if cmd == 'M'
      $mark[n.to_i] = true
    else
      sum += s.parent(n.to_i)
    end
  end
  p sum
end

Measured memory_bytes: 16056
/*
t.me/ivanesipovvpered
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;

const double EPS = 1e-5;
const int mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;
const int maxn = 1e5 + 3;

ll gcd(ll a, ll b){
    if (b == 0ll)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a / gcd(a, b) )* b;
}

bool is_prime(ll a){
    if (a == 2 | a == 3 || a == 5 || a == 7) return true;
    if (a % 2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
        return false;
    for (ll i = 11; i * i <= a; i += 2){
        if (a % i == 0)
            return false;
    }
    return true;
}

ll binpow(ll a, int n){
    if (a == 0)
        return 1;
    if (a % 2 == 0){
        ll q = binpow(a, n / 2);
        return (q * q)  ;
    }else return (a * binpow(a, n - 1) ) ;
}





















main(){
    int n, w;
    cin >> n >> w;
    vi dp(maxn, INFLL), dr(maxn, INFLL);
    dp[0] = 0;
    dr[0] = 0;
    vi a(n), we(n);
    rep(i, n)
        cin >> we[i] >> a[i];
    rep(i, n){
        rer(j, a[i], maxn){
            dp[j] = min(dp[j],dr[j - a[i]] + we[i]);
        }
        dr = dp;
    }
    int maxx = 0;
    rep(i, maxn)
        if (dp[i] <= w)
        maxx = max(maxx, i);
    cout << maxx;


}


Measured memory_bytes: 1792
N = int(input())
lsa = list(map(int,input().split()))
lsb = []
joker = 0
for i in lsa:
    if i >=1 and i <=399:
        lsb.append('1')
    elif i >=400 and i <=799:
        lsb.append('2')
    elif i >=800 and i <=1199:
        lsb.append('3')
    elif i >=1200 and i <=1599:
        lsb.append('4')
    elif i >=1600 and i <=1999:
        lsb.append('5')
    elif i >=2000 and i <=2399:
        lsb.append('6')
    elif i >=2400 and i <=2799:
        lsb.append('7')
    elif i >=2800 and i <=3199:
        lsb.append('8')
    elif i >=3200:
        joker += 1
s1 = len(set(lsb)) 
s2 = s1+joker
print(max(s1,1),s2)

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

count = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
        count += 1

print(' '.join(list(map(str, a))))
print(count)

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

int main() {
    int n, q;
    cin >> n >> q;
    vector<priority_queue<int>> a(n);
    for (int i = 0; i < q; ++i) {
        int p, t;
        cin >> p >> t;
        if (p == 0) {
            int x;
            cin >> x;
            a[t].push(x);
        } else if (p == 1) {
            if (!a[t].empty()) cout << a[t].top() << endl;
        } else {
            if (!a[t].empty()) a[t].pop();
        }
    }
}



Measured memory_bytes: 4096
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    int n=s.size();
    rep(i,n){
        int nxt=(26+'a'-s[i])%26;
        if(nxt>k)continue;
        k-=nxt;
        s[i]='a';
    }
    int cur=s[n-1]-'a';
    cur=(cur+k)%26;
    s[n-1]='a'+cur;
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		City[] city = new City[M];
		Main main = new Main();
		for (int i=0;i<M;i++) {
			City c = main.new City();
			c.ken = sc.nextInt();;
			c.birth = sc.nextInt();
			city[i] = c;
			c.num = i;
		}
		Arrays.sort(city);
		int count =1;
		int befCity = city[0].ken;
		Map <Integer,String> map= new HashMap<Integer,String>(M*2);
		StringBuffer sb = new StringBuffer();
		sb.append(String.format("%06d", befCity));
		sb.append(String.format("%06d", count));
		map.put(city[0].num, sb.toString());
		for (int i=1;i<M;i++) {
			if (befCity!= city[i].ken) {
				count =1;
				befCity= city[i].ken;
			} else {
				count++;
			}
			sb = new StringBuffer();
			sb.append(String.format("%06d", befCity));
			sb.append(String.format("%06d", count));
			map.put(city[i].num, sb.toString());
		}
		Object[] num = map.keySet().toArray();
		Arrays.sort(num);
		for(int i=0;i<num.length;i++) {
			System.out.println(map.get(num[i]));
		}
	}

	public class City implements Comparable<City> {
		int ken ;
		int birth;
		int num;
		@Override
		public int compareTo(City o) {
			if (this.ken > o.ken) {
				return 1;
			}
			if (this.ken < o.ken) {
				return -1;
			}
			if (this.birth < o.birth) {
				return -1;
			}
			if (this.birth > o.birth) {
				return 1;
			}
			return 0;
		}

	}
}

Measured memory_bytes: 172224
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const long long mod=1e9+7;
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; }
int dp[1005][1005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);    
int q=0;
cin>>q;
vector<vector<string>> s(q,vector<string>(2));
for(int i=0;i<q;i++)cin>>s.at(i).at(0)>>s.at(i).at(1);
for(int pos=0;pos<q;pos++){
    memset(dp,0,sizeof(dp));
    string a=s.at(pos).at(0),b=s.at(pos).at(1);
    for(int i=0;i<(int)a.size();i++){
        for(int j=0;j<(int)b.size();j++){
            if(a.at(i)==b.at(j))dp[i+1][j+1]=dp[i][j]+1;
            else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
        }
    }
    cout<<dp[a.size()][b.size()]<<endl;
}

}


Measured memory_bytes: 7200
'use strict' 

function main(input) {
  //ABC, ARC, AGC
  input = ~~input.split('\n')[0]

  let ans = 'AGC'
  if (input < 1200) {
    ans = 'ABC'
  } else if (input < 2800) {
    ans = 'ARC'
  }

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int n;
long long sum[200005];
long long res=1e18;
void Get(int l,int r,long long &fir,long long &sec)
{
	long long res=1e18;
	int lef=l,rig=r-1;
	while(lef<=rig)
	{
		int mid=lef+rig>>1;
		long long a=sum[mid]-sum[l-1];
		long long b=sum[r]-sum[mid];
		if(abs(a-b)<res)
		{
			res=abs(a-b);
			fir=a;
			sec=b;
		}
		if(a<=b) lef=mid+1;
		else rig=mid-1;
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		sum[i]=a+sum[i-1];
	}
	for(int i=2;i<=n-2;i++)
	{
		long long a,b;
		Get(1,i,a,b);
		long long c,d;
		Get(i+1,n,c,d);
		long long cand=max(max(a,b),max(c,d))-min(min(a,b),min(c,d));
		res=min(res,cand);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,ans=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((a[i]+a[j]>a[k])&&(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]))
                {
                    ans++;
                    //cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{ int n,a,b,count=0;
 cin>>n>>a>>b;
  for(int i=a;i<=b;i++)
  {if((i%n)==0)
    {count++;
    }
  }
  if(count>0)
   {cout<<"OK";
   }
  else
    {cout<<"NG";
    }

    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1, dy = y2 - y1;
  int x3 = x2 - dy, y3 = y2 + dx;
  int x4 = x3 - dx, y4 = y3 - dy;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


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

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

#define rrep(i, n) for (int i = n; i >= 0; --i)

#define rep_(i, m, n) for (int i = m; i < n; ++i)

#define INF 2e9

#define ll long long

//const ll MOD = 1000000007;

//const  long double PI=(acos(-1));

//const  long double EPS=0.0000000001;

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

    vector<vector<int>> list(n+1);

    string ac = "AC";
    string wa = "WA";
    rep(i, m)
    {
        int p;
        string t;
        cin >> p >> t;
        p--;
        if (t == ac)
        {
            list[p].push_back(1);
        }
        else
            list[p].push_back(0);
    }

    int ac_cnt = 0;
    int wa_cnt = 0;
    int cnt = 0;

    rep(i,n){
        for(auto x: list[i]){
            if(x == 1){
                ac_cnt++;
                wa_cnt+=cnt;
                break;
            }
            else{
                cnt++;
            }
        }
        cnt = 0;
    }

    cout << ac_cnt << " " << wa_cnt << endl;

    return 0;
}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main()
{
	int a,b,m=2000,n=2000,i;
	for(i=0;i<3;i++){
		cin>>a;
		if(m>a){
			m=a;
		}
	}
	for(i=0;i<2;i++){
		cin>>b;
		if(n>b){
			n=b;
		}
	}
	cout<<m+n-50<<endl;
	return 0;
}

Measured memory_bytes: 3076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {
	public static void main( String[] args ) throws IOException
    {
        BufferedReader br = new BufferedReader(
                                new InputStreamReader( System.in ) );
        String str = br.readLine();
        int a = -1;
        int b = -1;
        char c[] = str.toCharArray();
        for(int i = 2; i < c.length; i++){
        	if(c[i] == c[i-1]){
        		a = i;
        		b = i+1;
        		break;
        	} else if(c[i] == c[i-2]){
        		a = i-1;
        		b = i+1;
        		break;
        	}
        }
        if(c[0] == c[1]){
        	a = 1;
        	b = 2;
        }
        System.out.println(a+" "+b);
	}
}

Measured memory_bytes: 10708
#include<iostream>
#include<algorithm>//next_permutation
#include<cmath>
using namespace std;

int main(){
	int N;
	double sum = 0.0;
	int num = 0;
	int i;
	scanf("%d",&N);

	int arrange[2][N];
	int array[N];

	for(i=0;i<N;i++){
		array[i] = i;
	}

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

    do{
		 double temp = 0;
        for(int i=0; i<N-1; i++){
			temp = sqrt(pow(arrange[0][array[i]]-arrange[0][array[i+1]],2.0)+pow(arrange[1][array[i]]-arrange[1][array[i+1]],2.0));
            sum += temp;
        }
		num++;

    }while(next_permutation(array,array+N));
	printf("%.8f",sum/num);
    return 0;
}

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

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

    long long int a, b;
    cin >> a >> b;
    long long int g = __gcd(a, b);
    long long int n = g;
    long long int c = 1;
    for (long long int i = 2; i <= sqrt(g) + 1; i++)
    {
        if (n % i == 0) c++;
		while (n % i == 0)
        {
			n /= i;
		}
        if (n == 1) break;
	}
    if (n != 1) c++;
    cout << c << endl;

    return 0;
}

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

using namespace std;
int main()
{




    long long ai,t,n,a,A,sum=0,b,B,c=0,k,e,f,g;



    cin >> a >> b;

    for(long long i=0;i<b;i++)
    {
        cin >> n;
        sum+=n;

    }

    if(sum == a)
        cout << "0";
    else if(sum > a)
        cout << "-1";
    else
    {
        cout << a-sum;

    }







return 0;
}

Measured memory_bytes: 3652
import sys
h, w = map(int, input().split())
grid = [list('.' + input() + '.') for _ in range(h)]
grid.insert(0, list('.'*(w+2)))
grid.append(list('.'*(w+2)))

for y in range(1, h+1):
  for x in range(1, w+1):
    if grid[y][x] == '#':
      if grid[y-1][x] == '.' and grid[y][x-1] == '.' and grid[y][x+1] == '.' and grid[y+1][x] == '.':
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 3064
n = int(input())
 
i = [10, 100, 1000, 10000,100000]
digit = 0
p = [0, 9, 9, 909, 909, 90909]
for j in i:
  if j > n:
    break
  else:
    digit += 1
 
if digit%2 == 1:
  print(p[digit])
elif digit == 0:
  print(n)
else:
  
  print(p[digit]+n-i[digit-1]+1)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
static std::vector<long long int> factorial;
static std::vector<long long int> inverse;
constexpr long long int MOD = 1000000007;
void initialize() {
	factorial = std::vector<long long int>(200001, 1);
	inverse = std::vector<long long int>(200001, 1);
	auto inv = inverse;
	for (auto i = 2; i < factorial.size(); ++i) {
		factorial[i] = i * factorial[i - 1] % MOD;
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
		inverse[i] = inv[i] * inverse[i - 1] % MOD;
	}
}
long long int combination(int n, int r) {
	return factorial[n] * inverse[r] % MOD * inverse[n - r] % MOD;
}
long long int power(long long int base, long long int exp) {
	switch (exp) {
	case 0: return 1LL;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp >> 1)* power(base, exp & 1) % MOD;
	}
}
int main() {
	initialize();
	int n; std::cin >> n;
	std::vector<std::vector<int>> tree(n);
	for (auto i = 1; i < n; ++i) {
		int a, b; std::cin >> a >> b;
		tree[a - 1].push_back(b - 1);
		tree[b - 1].push_back(a - 1);
	}
	std::vector<int> sub_tree_size(n, 1), parent(n, -1), order; parent[0] = 0; order.reserve(n);
	std::vector<long long int> from_leaf(n, 1);
	std::stack<int> stack; stack.push(0);
	while (!stack.empty()) {
		const auto top = stack.top(); stack.pop();
		order.push_back(top);
		for (const auto next : tree[top]) if (parent[next] == -1) {
			parent[next] = top;
			stack.push(next);
		}
	}
	for (auto i = 1; i < order.size(); ++i) {
		const auto c = order[n - i];
		const auto p = parent[c];
		from_leaf[p] = combination(sub_tree_size[p] - 1 + sub_tree_size[c], sub_tree_size[c]) * from_leaf[p] % MOD * from_leaf[c] % MOD;
		from_leaf[p] %= MOD;
		sub_tree_size[p] += sub_tree_size[c];
	}
	std::vector<long long int> from_root(n, 1);
	std::vector<long long int> result(n); result[0] = from_leaf[0];
	for (auto i = 1; i < n; ++i) {
		const auto c = order[i];
		const auto p = parent[order[i]];
		const auto sub_else = sub_tree_size[p] - sub_tree_size[c] - 1;
		const auto tap_else = from_leaf[p] * power(from_leaf[c] * combination(sub_tree_size[p] - 1, sub_tree_size[c] % MOD) % MOD, MOD - 2) % MOD;
		from_root[c] = from_root[p] * tap_else % MOD * combination(n - sub_tree_size[c] - 1, sub_else) % MOD;
		result[c] = from_root[c] * from_leaf[c] % MOD * combination(n - 1, sub_tree_size[c] - 1) % MOD;
	}
	for (const auto c : result) std::cout << c << '\n';
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < i; ++j){
      if(abs(A[i]-A[j])%(N-1)) continue;
      cout << A[j] << " " << A[i] << endl;
      return 0;
    }
  }
}



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

int main(){
  ll K;cin >> K;
  ll X = 0;
  ll cnt = 0;
  while(1){
    X = 10*X + 7;
    X %= K;
    cnt ++;
    if(X==0){
      cout << cnt << endl;
      return 0;
    }
    if(cnt>K){
      cout << -1 << endl;
      return 0;
    }
  }
}

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

int main()
{
    int n = 0;
    int k = 0;
    std::cin >> n >> k;
    
    int rangeSum = 0;
    std::queue<int> diceQueue;
    
    for(int index = 0; index < k; ++index)
    {
        int pn = 0;
        std::cin >> pn;
        rangeSum += pn;
        diceQueue.emplace(pn);
    }
    
    int maxSum = rangeSum;
    
    for(int index = k; index < n; ++index)
    {
        int pn = 0;
        std::cin >> pn;
        rangeSum += (pn - diceQueue.front());
        maxSum = std::max(maxSum, rangeSum);
        diceQueue.pop();
        diceQueue.emplace(pn);
    }
    
    printf("%f", (k + maxSum) / 2.0);
}

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

int main(){
	
	int n;
	cin>>n;
	int arr[n];
	for(int i = 0 ; i < n ; i++){
		
		cin>>arr[i];
	}
	bool flag = false;
	for(int i = 0 ; i < n ; i++){
		if( arr[i] % 2 == 0 && arr[i] % 3 != 0 && arr[i] % 5 != 0 ){
			flag = true;
			cout<<"DENIED"<<endl;
			break;
		}
	}
	if(flag == false){
		cout<<"APPROVED"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const ll INF=100000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
int main() {
	string s;
	int h,w;
	cin>>h>>w;
	rep(i,0,h){
		cin>>s;
		cout<<s<<endl;
		cout<<s<<endl;
	}
	return 0;
}


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

int main()
{
    long long n;
    cin >> n;
    int l = sqrt(n) + 1;
    for (int i = l ; i > 0; i--)
    {
        if (n % i == 0)
        {
            cout << i - 1 + n / i - 1 << "\n";
            return 0;
        }
    }
}

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

int main() {
#ifdef HOME
	freopen("abc85a.in", "r", stdin);
	freopen("abc85a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	string str;

	cin >> str;
	str[3] = '8';
	cout << str << endl;	

	return 0; }

Measured memory_bytes: 256