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

template<class T, class E> struct LazySegmentTree {
    using F = function<T(T, T)>;
    using G = function<T(T, E)>;
    using H = function<E(E, E)>;
    using P = function<E(E, int)>;
private :
    int n;
    F f;
    G g;
    H h;
    P p;
    T id1;
    E id0;
    vector<T> node;
    vector<E> lazy;
public :
    LazySegmentTree (int sz, F f, G g, H h, T id1, E id0, P p)
            : f(f), g(g), h(h), id1(id1), id0(id0), p(p) {
        n = 1; while (n < sz) n *= 2;
        node.resize(2*n-1, id1);
        lazy.resize(2*n-1, id0);
    }

    LazySegmentTree (vector<T> v, F f, G g, H h, T id1, E id0, P p)
            : f(f), g(g), h(h), id1(id1), id0(id0), p(p) {
        n = 1; while (n < (int)v.size()) n *= 2;
        node.resize(2*n-1, id1);
        lazy.resize(2*n-1, id0);
        for (int i = 0; i < (int)v.size(); i++){
            node[i+n-1] = v[i];
        }
        for (int i = n-2; i >= 0; i--) {
            node[i] = f(node[2*i+1], node[2*i+2]);
        }
    }

    inline void eval (int len, int k) {
        if (lazy[k] == id0) return;
        if (k*2+1 < n*2-1) {
            lazy[2*k+1] = h(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = h(lazy[2*k+2], lazy[k]);
        }
        node[k] = g(node[k], p(lazy[k], len));
        lazy[k] = id0;
    }

    T update (int a, int b, E x, int k, int l, int r) {
        eval(r-l, k);
        if (r <= a || b <= l) return node[k];
        if (a <= l && r <= b) {
            lazy[k] = h(lazy[k], x);
            return g(node[k], p(lazy[k], r-l));
        }
        return node[k] = f(update(a, b, x, 2*k+1, l, (l+r)/2),
                           update(a, b, x, 2*k+2, (l+r)/2, r));
    }

    T update (int a, int b, E x) {
        return update(a, b, x, 0, 0, n);
    }

    T query (int a, int b, int k, int l, int r) {
        eval(r-l, k);
        if (r <= a || b <= l) return id1;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }

    T query (int a, int b) {
        return query(a, b, 0, 0, n);
    }

};


int main() {
    int n, q;
    cin >> n >> q;
    
    const long long id1 = 0LL;
    const long long id0 = INT64_MAX;
    auto f = [](long long a, long long b) { return a + b; };
    auto g = [&](long long a, long long b) { return (b == id0 ? a : b); };
    auto h = [&](long long a, long long b) { return (b == id0 ? a : b); };
    auto p = [](long long a, int b) { return (long long)a*b; };
    LazySegmentTree<long long, long long> seg(vector<long long>(n, 0LL), f, g, h, id1, id0, p);


    while (q--) {
        int op;
        cin >> op;
        if (op == 0) {
            int s, t;
            long long x;
            cin >> s >> t >> x;
            seg.update(s, t+1, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << seg.query(s, t+1) << endl;
        }
    }
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){
   
    int n;cin>>n;
    vi a(n);rep(i,n)cin>>a[i];

    vi c(3,0);
    int p;
    ll ans=1;

    rep(i,n){
        p=0;
        rep(j,3){
            if(a[i]==c[j]){
                p++;
                if(p==1)c[j]++;
            }
        }
        ans=(ans*p)%MOD;
        cerr<<"i="<<i<<" c="<<c[0]<<" "<<c[1]<<" "<<c[2]<<" ans="<<ans<<endl;
    }

    cout<<ans<<endl;
    
    return 0;
}

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

int main()
{
	long long X;
	cin >> X;
	for (long long i = 1; i <= X; i++) {
		if ((i * (i + 1)) / 2 >= X) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;

}


Measured memory_bytes: 3576
N, K = map(int, input().split())
A = list(map(int, input().split()))

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)

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

int nextch(int);

int slen=0;

int main(void)
{
	int i, j, plen, flag=0;
	char s[101], p[101];
	
	gets(s); gets(p);
	slen = strlen(s);
	plen = strlen(p);
	
	for(i=0; i<slen && flag==0; i++) {
		flag = 1;
		for(j=0; j<plen; j++) {
			if(s[nextch(i+j)] != p[j]) {
				flag = 0;
				break;
			}
		}
	}
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}

int nextch(int num)
{
	if(num >= slen) return num - slen;
	else return num;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll temp;
    ll ans = 0;
    map<ll, ll> fact;
    cin >> N;
    temp = N;
    for(ll i = 2;i * i <= N;i++) {
        while(temp % i == 0) fact[i]++, temp /= i;
    }
    if(temp > 1) fact[temp]++;
    iter(i, fact) {
        ll count;
        temp = i.second;
        for(count = 1;temp >= count;temp -= count++);
        ans += count - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int a[20]={0,100,1,2,3,4,5,6,7,8,9,10,11,12};
int main(){
	string s;
	cin>>s;
	int min=200005;
	int max=-1;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A'){
			if(i<min)
				min=i;
		}
		else if(s[i]=='Z'){
			if(i>max)
				max=i;
		}
	}
	cout<<max-min+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n;
int main()
{
	cin>>n;
	if(n%10==9) n-=8;
	else if(n%10==1) n+=8;
	if(n/100==9) n-=800;
	else if(n/100==1) n+=800;
	if(n/10%10==1) n+=80;
	else if(n/10%10==9) n-=80;
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,m;
  while(1){
   cin>>n;
   if(n==0)return 0;
   V<V<bool>> visited(21,vector<bool>(21,false));
   V<P> d(n);
   for(int i=0;i<n;i++){
       cin>>d[i].fi>>d[i].se;
   }
   cin>>m;
   int nowx=10,nowy=10;
    char c;
    int t;
   for(int i=0;i<m;i++){
       cin>>c;
       cin>>t;
       if(c=='N'){
           for(int j=1;j<=t;j++)visited[nowx][nowy+j]=1;
           nowy+=t;
       }
       else if(c=='S'){
           for(int j=1;j<=t;j++)visited[nowx][nowy-j]=1;
           nowy-=t;
       }
       else if(c=='W'){
           for(int j=1;j<=t;j++)visited[nowx-j][nowy]=1;
           nowx-=t;
       }
       else{
            for(int j=1;j<=t;j++)visited[nowx+j][nowy]=1;
           nowx+=t;
       }
   }
   bool ok=true;
   for(int i=0;i<n;i++){
       if(!visited[d[i].fi][d[i].se])ok=false;
   }
   if(ok)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll n , m ,k;
ll nbr;

int main()
{
	IOS;
   ll n,w;
   cin >> n >> w;
   vector<ll> V,W;
   for(int i=0;i<n;i++)
   {
       ll w,v;
       cin >> w >> v;
       W.push_back(w);
       V.push_back(v);
   }
   vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=w;j++)
       {
           if(W[i-1]>j)
           {
               dp[i][j]=dp[i-1][j];
           }
           else
            dp[i][j]=max(dp[i-1][j],V[i-1]+dp[i-1][j-W[i-1]]);
       }
   }
   cout << dp[n][w];


    return 0;
}


Measured memory_bytes: 80256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp33 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var B = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var C = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Array.Sort(A);
            Array.Sort(B);
            Array.Sort(C);

            var B_cummulative = new long[N];
            int index_A = 0;
            int index_B = 0;

            for (index_B = 0; index_B < N; index_B++) {
                long value = 0;

                if (index_B >= 1) {
                    value = B_cummulative[index_B - 1];
                }

                while (true) {
                    if (index_A < N && A[index_A] < B[index_B]) {
                        value++;
                        index_A++;
                    } else {
                        break;
                    }
                    if (index_A == N) {
                        break;
                    }
                }

                B_cummulative[index_B] = value;
            }


            var C_cummulative = new long[N];
            index_B = 0;
            int index_C = 0;

            for (index_C = 0; index_C < N; index_C++) {
                long value = 0;

                if (index_C >= 1) {
                    value = C_cummulative[index_C - 1];
                }

                while (true) {
                    if (index_B < N && B[index_B] < C[index_C]) {
                        value += B_cummulative[index_B];
                        index_B++;
                    } else {
                        break;
                    }
                    if (index_B == N) {
                        break;
                    }
                }

                C_cummulative[index_C] = value;
            }

            Console.WriteLine(C_cummulative.Sum());

        }
    }
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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;}

llong k;
vector<llong> A;

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

    cin >> k;
    A.resize(k);
    rep(i, k) cin >> A[k - i - 1];

    llong l = 2, r = 2;
    for (int i = 0; i < k; ++i) {
        l = (l + A[i] - 1) / A[i] * A[i];
        r = (r / A[i]) * A[i] + A[i] - 1;
        if (l > r) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << l << " " << r << endl;

    return 0;
}

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

#define int long long

#define MOD 1000000007

int memo[1010][1010];

int h, w, k;

bool isOK(int bit){
    for(int i = 0;i < w-1;i++){
        if(((bit & (1 << i)) != 0) && ((bit & (1 << (i+1))) != 0)){
            return false;
        }
    }

    return true;
}

int dp(int i, int j){
    if(i == h){
        if(j == k){
            return 1;
        }else{
            return 0;
        }
    }

    if(memo[i][j] != -1){
        return memo[i][j];
    }

    int ans = 0;
    for(int x = 0;x < (1 << (w-1));x++){
        if(isOK(x)){
            if(j == w-1){
                if((x & (1 << (j-1))) != 0){
                    ans += dp(i+1, j-1);
                    ans %= MOD;
                }else{
                    ans += dp(i+1, j);
                    ans %= MOD;
                }
            }else if(j == 0){
                if((x & (1 << j)) != 0){
                    ans += dp(i+1, j+1);
                    ans %= MOD;
                }else{
                    ans += dp(i+1, j);
                    ans %= MOD;
                }
            }else{
                if((x & (1 << (j-1))) != 0){
                    ans += dp(i+1, j-1);
                    ans %= MOD;
                }else if((x & (1 << j)) != 0){
                    ans += dp(i+1, j+1);
                    ans %= MOD;
                }else{
                    ans += dp(i+1, j);
                    ans %= MOD;
                }
            }
        }
    }

    return memo[i][j] = ans;
}

signed main(){
    cin >> h >> w >> k;
    k--;

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

    cout << dp(0, 0) << endl;

    return 0;
}


Measured memory_bytes: 8192
N = int(input())
ns = list(map(int, input().split()))

newlist = [0 for i in range(N)]
cou = 0
while all([a == 0 for a in ns]) == False:
    y = 0
    for i,num in enumerate(ns):
        if num == 0 and y == 0:
            continue
        elif num != 0:
            ns[i] -= 1  
            y = 1
        
        if num == 0 and y == 1:
            break
        
    cou+=1

print(cou)
    

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int n;
	cin >> n;
	string s;cin >> s;
	for(int S = 0;S<2 ;++S)
	{
		for(int W = 0;W < 2;W++)
		{
			string ans;
			if(S==0&&W==0)ans="SS";
			if(S==1&&W==0)ans="WS";
			if(S==0&&W==1)ans="SW";
			if(S==1&&W==1)ans="WW";

			for(int i=1;i<n-1;i++)
			{
				if(s[i]=='o'&&ans[i]=='S')
				{
					ans.push_back(ans[i-1]);
				}
				if(s[i]=='o'&&ans[i]=='W')
				{
					ans.push_back(ans[i-1]=='S'?'W':'S');
				}
				if(s[i]=='x'&&ans[i]=='S')
				{
					ans.push_back(ans[i-1]=='S'?'W':'S');
				}
				if(s[i]=='x'&&ans[i]=='W')
				{
					ans.push_back(ans[i-1]);
				}
			}
			bool isans = true;
			if(ans[0]=='S')
			{
				if(s[0]=='o'&&ans[1]!=ans[n-1])isans=false;
				if(s[0]=='x'&&ans[1]==ans[n-1])isans=false;
			}
			if(ans.back()=='S')
			{
				if(s.back()=='o'&&ans[0]!=ans[n-2])isans=false;
				if(s.back()=='x'&&ans[0]==ans[n-2])isans=false;
			}
			if(ans[0]=='W')
			{
				if(s[0]=='o'&&ans[1]==ans[n-1])isans=false;
				if(s[0]=='x'&&ans[1]!=ans[n-1])isans=false;
			}
			if(ans.back()=='W')
			{
				if(s.back()=='o'&&ans[0]==ans[n-2])isans=false;
				if(s.back()=='x'&&ans[0]!=ans[n-2])isans=false;
			}
			if(isans)
			{
				cout<<ans<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}
	return 0;
}

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

typedef long long ll;
using namespace std;
const ll m = 1e9 + 7;
ll solve(ll x, ll y) {
	ll X = x * x;
	ll Y = y * y;
	return X + Y;
	
}
int main() {
	int k; cin >> k;
	
	int val = 7 % k;
	for (int i = 1; i < 1e7; ++i) {
		if (val == 0) {
			cout << i << endl;
			return 0;
		}
		val = (val * 10 + 7) % k;
	}
	cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3528
times = [int(input()) for i in range(5)]
ans = 0
minutes = []
for i in range(len(times)):
  ans += times[i]
  if (times[i] % 10) != 0:
    minutes.append(str(times[i])[-1])

minutes.sort(reverse=True)

for j in range(len(minutes) - 1):
  ans += 10 - int(minutes[j])
print(ans)


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

const int m =2019;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(),s.end());
  int x=1,tot=0;
  vector<int> cnt(m);
  ll ans = 0;
  rep(i,n){
    cnt[tot]++;
    tot += (s[i]-'0')*x;
    tot %= m;
    ans+=cnt[tot];
    x=x*10%m;
  }
  cout<< ans << "\n";
  return 0;
}

Measured memory_bytes: 3764
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  [n, k, s] <- getIntList

  when (k /= 0) $ putStr (show s)
  replicateM_ (k-1) $ putStr (" " ++ show s)

  let x = if s == 10^9 then 1 else s + 1

  when (k /= n) $ do
    if (k == 0)
      then putStr (show x)
      else putStr (" " ++ show x)
  replicateM_ (n - k - 1) $ putStr (" " ++ show x)

  putStrLn ""

Measured memory_bytes: 2044
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
public class UnionFind {
    private int[] par, rank; //親、木の深さ

    public UnionFind(int size) { //初期化
        par = new int[size];
        rank = new int[size];
        for (int i = 0; i < size; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    public void Unite(int x, int y) { //xが属しているグループとyが属しているグループを統合する
        //親が同じなら何もしない
        x = Find(x);
        y = Find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }    
    }

    public bool IsSameGroup(int x, int y) { //xとyが同じグループに属しているかどうか
        return Find(x) == Find(y);
    }

    public int Find(int x) { //ノードxの根を求める
        if(par[x] == x) {
            return x;
        }
        else {
            return par[x] = Find(par[x]);
        }
    }

    public int Size(int x) => par[Find(x)];
}

class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        int K = cin.Int();
        int L = cin.Int();

        var foot = new UnionFind(N);
        var train = new UnionFind(N);
        for (int i = 0; i < K; i++) {
            int p = cin.Int() - 1;
            int q = cin.Int() - 1;
            foot.Unite(p, q);
        }
        for (int i = 0; i < L; i++) {
            int r = cin.Int() - 1;
            int s = cin.Int() - 1;
            train.Unite(r, s);
        }

        var dic = new Dictionary<Tuple<int, int>, int>();
        for (int i = 0; i < N; i++) {
            var tmp = new Tuple<int, int>(foot.Find(i), train.Find(i));
            if(dic.ContainsKey(tmp)) dic[tmp]++;
            else dic[tmp] = 1;
        }

        for (int i = 0; i < N; i++) {
            var tmp = new Tuple<int, int>(foot.Find(i), train.Find(i));
            Console.Write(dic[tmp] + " ");
        }
        Console.WriteLine();
        Console.ReadLine();
    }
}

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

using namespace std;

int main()
{
	int a[1000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int ans = 1;
	int k = a[0];
	for (int i = 1; i < n; i++)
	{
		if (k <= a[i])
		{
			ans++;
			k = a[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long int n,m,i,j;
long long int a[101],b[101],f[101][100001];
int main()
{
    cin >>n>>m;
    for (i=1;i<=n;i++) cin >>a[i]>>b[i];
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        {
            f[i][j]=f[i-1][j];
            if (j-a[i]>=0) f[i][j]=max(f[i][j],f[i-1][j-a[i]]+b[i]);
        }
    }
    cout <<f[n][m];
    return 0;
}


Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a[n],c;
  for(int i=0;i<n;i++){
     cin >> c;
     c=c-i-1;
     a[i]=c;
  }
  sort(a,a+n);
  long long int l=n/2;
  if(n%2==0) {
    long long int k=(a[l]+a[l-1])/2;
    long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=abs(a[i]-k);
    }
    cout << sum<<endl;
  }
  else{
    long long int k=a[l];
    long long int sum=0;
    for(int i=0;i<n;i++){
        sum+=abs(a[i]-k);
    }
    cout <<sum <<endl;
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int cnt[26] = {};
    REP(i,4){
        cnt[S[i]-'A']++;
    }
    int check = 0;
    REP(i,26){
        if(cnt[i] == 2) check++;
    }
    if(check == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
// #define mod 1000000007
#define mod 998244353
using namespace std;
ll dp[3001][3001];

int main()
{
	ios::sync_with_stdio(false);
	int n, s;
	cin >> n >> s;
	int a[n + 1];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i + 1];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= s; j++)
		{
			dp[i][j] = 2 * dp[i - 1][j];
			if (j - a[i] >= 0)
			{
				dp[i][j] += dp[i - 1][j - a[i]];
			}
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][s] << endl;
	return 0;
}

Measured memory_bytes: 73936
#include <iostream>
#include <vector>
#define MAX_N 100001

using namespace std;

vector<bool> IsPrime(MAX_N, true);

// エラトステネスの篩
void get_primes() {
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i*i <= MAX_N; i++) {
        if (IsPrime[i]) {
            for (int j = i*i; j <= MAX_N; j += i) {
                IsPrime[j]= false;
            }
        }
    }
}

int main() {
    int Q, l, r;
    vector<int> cnt(MAX_N, 0);

    get_primes();

    for (int i = 3; i <= MAX_N; i += 2) {
        if (IsPrime[i] && IsPrime[(i+1)/2]) { cnt[i]++; }
    }
    // 2017 に似てる数の累積和をとっている
    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    cin >> Q;

    while (Q--) {
        cin >> l >> r;
        cout << cnt[r] - cnt[l-1] << endl;
    }

    return 0;
}

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

int main()
{
	ll N,K;
	cin >> N >> K;
	ll ans = 0;
	if (K % 2 == 0)
	{
		ll cnt1;
		if (N % K >= K/2)
		{
			cnt1 = N / K + 1;
		}
		else
		{
			cnt1 = N / K;
		}

		ans += cnt1 * cnt1 * cnt1;
	}

	ll cnt2 = N / K;
	ans += cnt2 * cnt2 * cnt2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut stack: Vec<usize> = Vec::new();
    let mut stack2: Vec<(usize, usize, usize)> = Vec::new();
    let mut total: usize = 0;
    for (i, &c) in a.iter().enumerate() {
        if c == '\\' {
            stack.push(i);
        } else if c == '/' {
            if let Some(start) = stack.pop() {
                let area = i - start;
                total += area;

                let mut sum = area;
                while !stack2.is_empty() {
                    let &(s, _, w) = stack2.last().unwrap();
                    if s < start {
                        break;
                    }
                    sum += w;
                    stack2.pop().unwrap();
                }
                stack2.push((start, i, sum));
            }
        }
    }

    let mut result = String::new();
    result.push_str(&format!("{}\n", total));
    result.push_str(&format!("{}", stack2.len()));
    for (_, _, w) in stack2 {
        result.push_str(&format!(" {}", w));
    }
    return result.trim().to_string();
}



Measured memory_bytes: 5040
n=int(input())
A=list(map(int, input().split()))

plus=0
minus=0
for i in A:
    if i<0:
        minus+=1


value=999999999999999999999999999999
for num1,i in enumerate(A):
    if abs(i)<value:
        absmin=num1
        value=abs(i)

count=0
if minus%2==0:
    for i in A:
        count+=abs(i)
else:
    for num,i in enumerate(A):
        if num==absmin:
            count+=-abs(i)
        else:
            count+=abs(i)
        #print(count)

print(count)   

Measured memory_bytes: 14412
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
 
  int main(){
 long double a;
    long double b;
    cin>>a>>b;
    long double c=a*b;
    lint ans=c;
    cout<<ans<<endl;
  }
      
      
    

  
          
  

Measured memory_bytes: 3852
import sys
input=lambda: sys.stdin.readline().rstrip()
k,n=map(int,input().split())
A=[int(i) for i in input().split()]
ans=k-(k-A[-1]+A[0])
for i in range(n-1):
  ans=min(ans,k-A[i+1]+A[i])
print(ans)


Measured memory_bytes: 26444
//Do what you can't.

import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main{
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter w = new PrintWriter(System.out);

    int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();
    int[] arr = in.nextIntArray(n);
    long fat = 0;
    for (int i = 0; i < n - 1; i++) {
      fat += Math.min((long)Math.abs(arr[i] - arr[i + 1]) * a, b);
    }
    w.println(fat);
    w.close();
  }
  static class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int snext() {
      if (snumChars == -1)
        throw new InputMismatchException();
      if (curChar >= snumChars) {
        curChar = 0;
        try {
          snumChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (snumChars <= 0)
          return -1;
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public long nextLong() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public int[] nextIntArray(int n) {
      int a[] = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    public String readString() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public String nextLine() {
      int c = snext();
      while (isSpaceChar(c))
        c = snext();
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isEndOfLine(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null)
        return filter.isSpaceChar(c);
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private boolean isEndOfLine(int c) {
      return c == '\n' || c == '\r' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N,K;
vector<ll> A;

int main() {
	cin >> N >> K;
	A.resize(N);
	for (ll n = 0; n < N; n++)cin >> A[n];
	sort(A.begin(), A.end(), [](ll a, ll b) {
		return a > b;
	});
	ll ans = 0;
	for (ll k = 0; k < K; k++)ans += A[k];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N 100000
#define MAX (1<<31)-1
using namespace std;
long long A[N]={0}, T[4*N], lazy[4*N]={0};

void build(int l, int r, int k) {
    if (l == r) {
        T[k] = A[l];
        return;
    }
    int mid = (l + r) / 2;
    build(l, mid, k * 2);
    build(mid + 1, r, k * 2 + 1);
    T[k] = min(T[2 * k], T[2 * k + 1]);
}
void pushdown(int k) {
    if (lazy[k]) {
        lazy[2*k] += lazy[k];
        lazy[2*k+1] += lazy[k];
        T[2*k] += lazy[k];
        T[2*k+1] += lazy[k];
        lazy[k] = 0;
    }
}
void updata(int L, int R, int data ,int l, int r ,int k) {
    if (L <= l && r <= R) {
        T[k] += data;
        lazy[k] += data;
        return;
    }
    int mid = (l + r) / 2;
    pushdown(k);
    if (mid >= L) updata(L, R, data, l, mid, 2*k);
    if (mid < R) updata(L, R, data, mid+1, r, 2*k+1);
    T[k] = min(T[2 * k], T[2 * k + 1]);
}
long long find(int L, int R, int l, int r, int k) {
    if (L <= l && r <= R) return T[k];
    int mid = (l + r) / 2;
    pushdown(k);
    long long ans = MAX;
    if (mid >= L) ans = min(ans, find(L, R, l, mid, k * 2));
    if (mid < R) ans = min(ans, find(L, R, mid + 1, r, k * 2 + 1));
    return ans;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    build(0, n-1, 1);
    int com, s, t, x, y;
    while (q--) {
        scanf("%d", &com);
        if (com == 0) {
            scanf("%d%d%d", &s, &t, &x);
            updata(s, t, x, 0, n-1, 1);
        }
        else {
            scanf("%d%d", &s, &t);
            printf("%ld\n", find(s, t, 0, n-1, 1));
        }
    }
    return 0;
}


Measured memory_bytes: 6804
#include <stdio.h>

int main(){
	long int H, W;
	scanf("%ld %ld",&H, &W);
	if(H==1 ||W==1){
		printf("1\n");
	}else if(H*W%2==0){
		printf("%ld\n",H*W/2);
	}else{
		printf("%ld\n",H*W/2+1);
	}
	return 0;
}

Measured memory_bytes: 128
def p_a():
    H, W, A, B = map(int, input().split())

    S = [[0] * W for _ in range(H)]

    if A == 0 and B == 0:
        for i in range(H):
            print(*S[i], sep="")
        exit()

    for i in range(H):
        for j in range(W):
            if A == 0:
                if i < B:
                    S[i][j] = 1
                continue
            elif B == 0:
                if j < A:
                    S[i][j] = 1
                continue

            if i // B == 1 and j // A == 1:
                S[i][j] = 1

            if i // B == 1:
                continue

            if j // A == 1:
                continue

            S[i][j] = 1

    for i in range(H):
        print(*S[i], sep="")


if __name__ == '__main__':
    p_a()


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    ll n, m, k;
    while(cin>>n>>m>>k, n){
        vector<vector<ll>> dp(n+10, vector<ll>(n*m+10, 0));
        dp[0][0]=1;
        for(int i=0; i<n; i++){
            for(int sum=0; sum<=n*m; sum++){
                for(int side=1; side<=m; side++){
                    if(sum+side>n*m) continue;
                    dp[i+1][sum+side]+=dp[i][sum];
                }
            }
        }

        double div=1;
        for(int i=0; i<n; i++) div/=m;

        double ans=0;
        for(ll i=0; i<=n*m; i++){
            if(i<=k) ans+=1.*dp[n][i]*div;
            else ans+=1.*dp[n][i]*div*(i-k);
            //cout << i << " " << dp[n][i] << endl;
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll power(ll n, ll p, ll mod) {
    ll ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * n % mod;
        n = n * n % mod;
        p >>= 1;
    }
    return ans;
}

class CombinationN {
   public:
    CombinationN(int n, int maxk) {
        N = n; K = maxk + 1; 
        fac = new ll[K];
        numerator = new ll[K];

        fac[0] = 1; numerator[0] = 1;
        REP(i, 1, K) {
            fac[i] = fac[i - 1] * i % MOD;
            numerator[i] = numerator[i - 1] * (n - i + 1) % MOD; 
        }
    }

    ll cnr(int k) {
        if (N - k < k) return cnr(N - k);
        return numerator[k] * power(fac[k], MOD - 2, MOD) % MOD;
    }

   private:
    int N, K;
    ll *fac, *numerator;
};

int main() {
    int X, Y; cin >> X >> Y;
    if (Y > X) swap(X, Y);

    int a = 0, b = 0;
    while (2 * Y > X) {
        Y -= 2; X--;
        b++;
    }

    if (Y * 2 != X) {
        cout << 0 << endl;
        return 0;
    }

    a = Y;

    CombinationN comb(a + b, min(a, b));
    cout << comb.cnr(min(a, b)) << endl;    

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int count = 0;
    bool flag = true;
    while (n--) {
        string s;
        cin >> s;
        if (s == "A") count++;
        else count--;

        if (count < 0) flag = false;
    }

    if (flag && count == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 3156
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
l = [K-Q] * N
for i in range(Q):
    l[A[i]-1] += 1
for i in range(N):
    if(l[i] >= 1):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 10448
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    vector<int> a(5);
    rep(i,5) cin >> a[i];
    int k; cin >> k;
    if (a[4]-a[0] <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int h, n; cin >> h >> n;
	vector<int> a(n);
	int s = 0;
	for (int i = 0; i < n; i++) cin >> a[i], s += a[i];
	cout << (s >= h ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<random>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 1e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 500+10
    int N;
int main(){
    cin>>N;
    cout<<(int)sqrt(N)*(int)sqrt(N);
}


Measured memory_bytes: 256
MAX = 300000001

N, K = map(int, input().split())
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print(xn[K - 1])
        return

    if xn[N - 1] < 0:
        print(abs(xn[N - K]))
        return

    ans = MAX

    for i in range(N):
        if N - 1 < i + K - 1:
            break

        if xn[i] < 0:
            if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
                ans = min(ans, abs(xn[i]))

            elif 0 <= xn[i + K - 1]:
                ans = min(ans,
                          2 * abs(xn[i]) + abs(xn[i + K - 1]),
                          abs(xn[i]) + 2 * abs(xn[i + K - 1]))

        elif 0 == xn[i]:
            ans = min(ans, xn[i + K - 1])

        elif 0 != i and xn[i - 1] < 0:
            ans = min(ans, xn[i + K - 1])

    print(ans)
    return


main()


Measured memory_bytes: 14100
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const double pi = 3.1415926535897932;
const double eps = 0.000000000001;
const int inf = 1145141919;
struct edge { int to, cost; };
typedef pair<int, int>P;
signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a + b >= c) {
		cout << b + c << endl;
	}
	else {
		int ans = 0;
		ans += b;
		ans += min(b, c);
		c = max(c - b, 0ll);
		ans += min(a, c);
		if (c)ans++;
		cout << ans << endl;
	}

}

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

int main(){
    int n, p[10], m = 0, sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        m = max(m, p[i]);
        sum += p[i];
    }
    cout << sum - m + m / 2 << endl;
}

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

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

    map<int, int> mp;

    for(int i=0; i<n; i++) {
        cin >> m;
        mp[m]++;
        mp[m+1]++;
        mp[m-1]++;
    }

    int ans = 0;

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        ans = max(ans, itr->second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string> // string??¨
#include <queue> // queue??¨
#include <utility> // pair??¨
#define MIN(a,b) ((a<b)?(a):(b)) // ????°??????????????????????
using namespace std;

typedef pair<string,int> ps; // string,int?????¢???ps??¨???????????????

int main(void){
	queue<ps> q; //?????¢??§?????????????????\????????????
	string s; // ???????????¬?????????
	int a; // ???????????¬?????°
	int t=0; // ????????????
	int n,qt; // ??????????????°??¨???????????????
	cin>>n>>qt; // ??????????????°??¨????????????????????\???
	while(n--){
		cin>>s>>a; // ?????????????????¨?????????????????\???
		q.push(ps(s,a)); // ?????¢??????????????????????????§?????????????????\????????¶?????????
	}

	while(!q.empty()){ // ?????\?????????????????£???????????????
		ps temp=q.front(); // ?????\???????????????????????????
		q.pop(); // ???????????????????????????
		t+=MIN(qt,temp.second); // ????????????????????????????????????????????????????°??????????
		temp.second-=qt; // ???????????????????????????????????£???????§??????????
		if(temp.second>0)q.push(temp); // ??????????????????????????£?????????????????°????????????
		else {
			cout<<temp.first<<" "<<t<<endl; // ????????????????????????????????¨?????¨???????????????
		}
	}
	return 0;
}

Measured memory_bytes: 6172
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0 && M == 0) break;
		vector<int> h(N), w(M);
		for (int i = 0; i < N; i++) cin >> h[i];
		for (int j = 0; j < M; j++) cin >> w[j];
		vector<int> hsum(N + 1), wsum(M + 1);
		for (int i = 1; i <= N; i++) hsum[i] = hsum[i - 1] + h[i - 1];
		for (int j = 1; j <= M; j++) wsum[j] = wsum[j - 1] + w[j - 1];
		map<int, int> m;
		for (int j = 0; j <= M; j++)
			for (int _j = j + 1; _j <= M; _j++)
				m[wsum[_j] - wsum[j]]++;
		ll cnt = 0;
		for (int i = 0; i <= N; i++)
			for (int _i = i + 1; _i <= N; _i++)
				cnt += m[hsum[_i] - hsum[i]];
		cout << cnt << endl;
	}
}

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

int main() {
 int n;
 cin >> n;
    
 vector<long long> r(n);
    rep(i,n) {
     cin >> r.at(i);
    }
 long long maxv = -10000000000;
 long long memo = r.at(0);
    
 for(int i = 1; i <n; i++) {
  maxv = max(maxv, r.at(i) - memo);
     memo = min(memo,r.at(i));
     
 }
    
    cout << maxv << endl;;
}


Measured memory_bytes: 4336