akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=2e9;
int n,num;
int a[202020],b[202020],v[202020];
map<int,int> mp;
ll ans;
struct Segment_Tree
{
	int minn[2020202],addv[2020202];
	void down(int p)
	{
		if (addv[p])
		{
			minn[p]+=addv[p];
			addv[p*2]+=addv[p];
			addv[p*2+1]+=addv[p];
			addv[p]=0;
		}
	}
	void build(int p,int l,int r)
	{
		if (l==r)
		{
			minn[p]=v[l];
			return;
		}
		int mid=(l+r)/2;
		build(p*2,l,mid); build(p*2+1,mid+1,r);
		minn[p]=min(minn[p*2],minn[p*2+1]);
	}
	void add(int p,int l,int r,int x,int y,int V)
	{
		if (x>y) return;
		down(p);
		if (x<=l && r<=y)
		{
			addv[p]+=V;
			return;
		}
		int mid=(l+r)/2;
		if (x<=mid) add(p*2,l,mid,x,y,V);
		if (y>mid) add(p*2+1,mid+1,r,x,y,V);

		down(p*2); down(p*2+1);
		minn[p]=min(minn[p*2],minn[p*2+1]);
	}
	int find(int p,int l,int r,int x,int y)
	{
		down(p);
		if (x<=l && r<=y) return minn[p];
		int mid=(l+r)/2,sss=inf;
		if (x<=mid) sss=min(sss,find(p*2,l,mid,x,y));
		if (y>mid) sss=min(sss,find(p*2+1,mid+1,r,x,y));
		return sss;
	}
}S;
void init()
{
	for (int i=1;i<=n;++i) b[i]=a[i];
	sort(b+1,b+1+n);
	for (int i=1;i<=n;++i) if (b[i]!=b[i-1])
	{
		++num;
		v[num]=b[i]; mp[b[i]]=num;
	}
	S.build(1,1,num);
	for (int i=1;i<=n;++i) 
		S.add(1,1,num,1,mp[a[i]]-1,1);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	init();
	for (int i=n;i>=1;--i)
	{
		S.add(1,1,num,1,mp[a[i]]-1,-1);
		ans+=(S.find(1,1,num,mp[a[i]],num) - a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

int main() {
  string s, t;
  cin >> s >> t;

  string ans = "";
  for (int i = 0; i < t.size(); i++) ans = ans + s[i] + t[i];
  if (s.size() != t.size()) ans = ans + s[s.size() - 1];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, M;
  std::cin >> N >> M;
  if (N < M) std::swap(N, M);

  ll ans = 0LL;
  if (N == 1 && M == 1) {
    ans = 1;
  } else if (M == 1) {
    ans = N - 2;
  } else if (M == 2) {
    ans = 0;
  } else {
    ans = (N-2) * (M-2);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int maxn=0,n,place=0;
	char st;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>st;
		if(st=='I')place++;
		else place--;
		if(place>maxn)maxn=place;
	}
	cout<<maxn<<endl;
	return 0;
}


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

int num[101];

int main() {
  int n;
  while ( cin >> n ) num[n]++;
  int maxn = 0;
  for ( int i = 1; i < 101; i++ ) maxn = max(maxn,num[i]);
  for ( int i = 1; i < 101; i++ ) {
    if ( num[i] == maxn ) cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A = list(map(int, readline().split()))

    A.sort()

    ans = (A[2] - A[0]) // 2 + (A[2] - A[1]) // 2
    A[0] += (A[2] - A[0]) // 2 * 2
    A[1] += (A[2] - A[1]) // 2 * 2

    if A[0] == A[1]:
        if A[0] < A[2]:
            ans += 1
    else:
        ans += 2

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9212
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define N 100005
#define mp map<int,int>
using namespace std;
int a[N];
ll ans;
int main() {
	int n;
	cin>>n;
	rep(i,1,n) cin>>a[i];
	rep(i,2,n-1){
		if(a[i-1]<a[i]&&a[i]<a[i+1]||a[i-1]>a[i]&&a[i+1]<a[i])
			ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

vector<int> G[200005];
vector<ll> ans(0);
vector<int> dist(200005, -1);

void dfs(int curr) {
    
    for (int nxt : G[curr]) {
        if (dist[nxt] != -1) continue;
        ans[nxt] = ans[nxt] + ans[curr];
        dist[nxt] = dist[curr] + 1;
        dfs(nxt);
    }
    return;
}

int main() {
    int n, q; cin >> n >> q;
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ans.resize(n);
    for (int i = 0; i < q; i++) {
        int p, x; cin >> p >> x;
        p--;
        ans[p] += x;
    }

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


Measured memory_bytes: 25088
# keyence2019B - KEYENCE String
def main():
    S = input()
    N = len(S)
    for i in range(N):
        for j in range(i, N):
            s = S[:i] + S[j:]
            if s == "keyence":
                print("YES")
                return
    print("NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <cstdio>

const int MaxV = 200000;

int N, V;
int A[MaxV + 5];

void init() {
  scanf("%d", &N);
  V = 2 * N - 1;
  for (int i = 1; i <= V; ++i)
    scanf("%d", &A[i]);
}

inline int check(int mid) {
  static int b[MaxV + 5];
  for (int i = 1; i <= V; ++i)
    if (A[i] >= mid) b[i] = 1;
    else b[i] = 0;
  static int pre[MaxV + 5], nxt[MaxV + 5];
  pre[1] = 1;
  for (int i = 2; i <= V; ++i)
    if (b[i] == b[i - 1]) pre[i] = pre[i - 1];
    else pre[i] = i;
  nxt[V] = V;
  for (int i = V - 1; i >= 1; --i)
    if (b[i] == b[i + 1]) nxt[i] = nxt[i + 1];
    else nxt[i] = i;
  if (pre[N] != N || nxt[N] != N) return b[N];
  int lpart = 0, rpart = V + 1;
  for (int i = 1; i < N; ++i) if (pre[i] != i) lpart = i;
  for (int i = V; i > N; --i) if (nxt[i] != i) rpart = i;
  if (lpart == 0 && rpart == V + 1) return b[1];
  else if (lpart == 0) return b[rpart];
  else if (rpart == V + 1) return b[lpart];
  else if (b[lpart] == b[rpart]) return b[lpart];
  else if (N - lpart < rpart - N) return b[lpart];
  else return b[rpart];
}

void solve() {
  int lbound = 1, rbound = V, ans = 0;
  while (lbound <= rbound) {
    int mid = (lbound + rbound) >> 1;
    if (check(mid) == 1) {
      ans = mid;
      lbound = mid + 1;
    } else rbound = mid - 1;
  }
  printf("%d\n", ans);
}

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

Measured memory_bytes: 4836
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int data[6][6]={0};
		for(int i=1;i<=5;i++){
			for(int j=1;j<=5;j++){
				cin>>data[j][i];
			}
		}
		for(int i=1;i<=5;i++){
			for(int j=1;j<=5;j++){
				data[j][i]+=data[j-1][i];
			}
		}
		for(int i=1;i<=5;i++){
			for(int j=1;j<=5;j++){
				data[j][i]+=data[j][i-1];
			}
		}
		int ans=0;
		for(int x=1;x<=5;x++){
			for(int y=1;y<=5;y++){
				for(int X=1;X<=5;X++){
					for(int Y=1;Y<=5;Y++){
						if(data[X][Y]+data[x-1][y-1]-data[X][y-1]-data[x-1][Y]==(X-x+1)*(Y-y+1)&&ans<(X-x+1)*(Y-y+1))ans=(X-x+1)*(Y-y+1);
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll mod = 998244353;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[3000005],R[3000005];
void make(){
	F[0] = 1;
	for(int i=1;i<3000005;i++) F[i] = F[i-1]*i%mod;
	R[3000004] = modpow(F[3000004],mod-2);
	for(int i=3000003;i>=0;i--) R[i] = R[i+1]*(i+1)%mod;
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}

int main(){
	ll n,m; cin >> n >> m;
	make();
	ll all = C(3*m+n-1,n-1);
	ll ans = 0;
	ans += n * C(m-1+n-1,n-1) % mod;
	ans = all-ans;
	
	for(int odd=0;odd<=m;odd++){
		if(odd > n) break;
		if(odd%2 != m%2) continue;
		ll coef = C(n,odd);
		ll zan = (3*m-odd)/2;
		ans += coef * C(zan+n-1,n-1) % mod;
	}
	ans -= all;
	cout << (ans%mod+mod)%mod << endl;
}

Measured memory_bytes: 47104
#include<iostream>

using namespace std;

int main(){
	
	int L,M,N,Rest;
	int month;
	bool flag;
	while(cin>>L,L!=0){
		Rest=0;
		flag=false;
		for(int i=1;i<=12;i++){
			cin>>M>>N;
			Rest=Rest+(M-N);
			if(Rest>=L){
				if(flag==false){
					month=i;
				}
				flag=true;
			}
		}
		if(flag){
			cout<<month<<endl;
		}else{
			cout<<"NA"<<endl;
		}
	}
	
}

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

using namespace std;

int main(void) {
    int H, W;
    vector<string> s(2010);
    cin >> H >> W;
    for (int i=0;i<H;i++) cin >> s[i];
    vector<vector<int>> lf(H,vector<int>(W,0)),rg(H,vector<int>(W,0));
    vector<vector<int>> up(H,vector<int>(W,0)),dn(H,vector<int>(W,0));
    vector<vector<int>> ans(H,vector<int>(W,0));

    for (int i=0;i<H;i++) {
        lf[i][0] = 0;
        for (int j=1;j<W;j++) if (s[i][j-1] == '.') lf[i][j] = lf[i][j-1] + 1;
        else lf[i][j] = 0;
    }
    for (int i=0;i<H;i++) {
        rg[i][W-1] = 0;
        for (int j=W-2;j>=0;j--) if (s[i][j+1] == '.') rg[i][j] = rg[i][j+1] + 1;
        else rg[i][j] = 0;
    }
    for (int j=0;j<W;j++) {
        dn[0][j] = 0;
        for (int i=1;i<H;i++) if (s[i-1][j] == '.') dn[i][j] = dn[i-1][j] + 1;
        else dn[i][j] = 0;
    }
    for (int j=0;j<W;j++) {
        up[H-1][j] = 0;
        for (int i=H-2;i>=0;i--) if (s[i+1][j] == '.') up[i][j] = up[i+1][j] + 1;
        else up[i][j] = 0;
    }
    for (int i=0;i<H;i++) for (int j=0;j<W;j++) {
        if (s[i][j] == '.') ans[i][j] = 1 + lf[i][j] + rg[i][j] + up[i][j] + dn[i][j];
    }
    int m = 0;
    for (int i=0;i<H;i++) m = max(m,*max_element(ans[i].begin(), ans[i].end()));
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 82944
s = input()
q = int(input())
t  ={}
for i in range(q):
    t[i]=input().split()
rv_count = 0
x = "X"
for d in t.values():
	if d[0] == "1":
		rv_count += 1
	else:
		if rv_count % 2 ==0:
			if d[1] == "1":
				x2 = d[2]+x
			else:
				x2 = x+d[2]
			x = x2
		else:
			red = d[2][::-1]
			if d[1] == "1":
				x2 = x + red
			else:
				x2 = red+x
			x = x2

if rv_count%2 == 0:
    xf = x.replace("X", s)
else:
	xf = x.replace("X", s)[::-1]
    
print(xf)

Measured memory_bytes: 57500
from fractions import gcd
from functools import reduce

MOD = 10 ** 9 + 7


def lcm(*nums):
    return reduce(lambda x, y: (x * y) // gcd(x, y), nums, 1)


# print(lcm(*[2, 3, 4])) -> 12

n = int(input())
a = list(map(int, input().split()))

l = lcm(*a)
ans = 0

for ai in a:
    ans += l // ai

print(ans % MOD)

Measured memory_bytes: 6100
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;
char s[4001];

int f(vector<int>& A, ll k) {
    int res = 0;
    int i = 1;
    int n = A.size();
    vector<int> visited(n + 1, 0);
    visited[i] = 1;
    int mod = 0;
    int repeat = -1;
    while(1) {
        if (mod == k) return i;
        if (!visited[A[i]]) {
            i = A[i];
            visited[i] = 1;
            mod++;
        } else {
            repeat = A[i];
            break;
        }
    }
    mod += 1;
 

    int start = 0;
    i = 1;
    while(i != repeat) {
        start++;
        i = A[i];
    }
    mod -= start;
    k =  (k - start) % mod;
    i = repeat;
    for (int j = 0; j < k; j++) {
        i = A[i];
    }
    return i;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    ll k;
    cin >> n >> k;
    vector<int> A(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    cout << f(A, k) <<endl;
    

    return 0;
}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll x,y;
    cin>>x>>y;
    if (y&1)
        cout<<"No\n";
    else if (y<x*2)
        cout<<"No\n";
    else if (y>x*4)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    return 0;
}


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

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

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({1ll*a*c, 1ll*a*d, 1ll*b*c, 1ll*b*d});
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(10);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3588
# -*- coding: utf-8 -*-
N = int(input())
An = list(map(int, input().split()))

# 尺取
ans = 0
l = 0
r = 0
Asum = An[0]
Axor = An[0]
while l < N and r < N:
    if Asum == Axor:
        ans += r-l+1
        r += 1
        if r < N:
            Asum += An[r]
            Axor ^= An[r]
    else:
        if l < N:
            Asum -= An[l]
            Axor ^= An[l]
        l += 1

print(ans)


Measured memory_bytes: 77772
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(ll i=1;i<=(n);++i)
#define ifr(i,n) for(ll i=(n)-1;i>=0;--i)
#define iFr(i,n) for(ll i=(n);i>0;--i)
//グローバルな場所に配列を置くとすべて0に初期化される。

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 int x,b;
 cin>>x>>b;
 if(x<=5){
   cout<<0;
 }
 else if(x<13){
   cout<<b/2;
 }
 else{
   cout<<b;
 }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    int b[200];
    int a[200],a_i=0;
    int sum=0;


    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d",&b[i]);
    }
    a[0]=b[0];
    for(int i=0;i<n-2;i++){
        a[i+1]=b[i]>b[i+1]?b[i+1]:b[i];
    }
    a[n-1]=b[n-2];
    for(int i=0;i<n;i++){
        //printf("i:%d %d\n",i,a[i]);
        sum+=a[i];
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	int n;
	int count;
	int num[2][15];
	
	while (cin >> n, n){
		count = 0;
		for (int i = 0; i < n; i++){
			cin >> num[0][i];
		}
		int ct, k = 0;
		while (1){
			for (int i = 0; i < n; i++){
				ct = 0;
				for (int j = 0; j < n; j++){
					if (num[k][i] == num[k][j]) ct++;
				}
				num[1 - k][i] = ct;
			}
			ct = 0;
			for (int i = 0; i < n; i++){
				if (num[0][i] == num[1][i]) ct++;
			}
			if (ct == n){
				break;
			}
			k = 1 - k;
			count++;
		}
		
		cout << count << endl << num[0][0];
		for (int i = 1; i < n; i++){
			cout << ' ' << num[0][i];
		}
		cout << endl;
	}
	return (0);
}

Measured memory_bytes: 1160
N = int(input())
Vs = [int(i) for i in input().split()]
Cs = [int(i) for i in input().split()]
res = 0
for i in range(len(Vs)):
    if Vs[i] - Cs[i] > 0:
        res += Vs[i] - Cs[i]
print(res)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string str;
	int n, r;
	int max, min;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>str;
		sort(str.begin(), str.end());
		min=atoi(str.c_str());
		reverse(str.begin(), str.end());
		max=atoi(str.c_str());
		cout << max-min << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {
	double r;
	double S;
	double L;
	cin >> r;

	S = M_PI * r*r;
	L = 2 * M_PI*r;

	cout <<fixed<<setprecision(6)<< S << " " << L << endl;

	return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll x,n;
	cin>>x>>n;
	ll pre[102]={0};
	ll dif=x;
	for (int i = 0; i < n; ++i)
	{
		ll u;
		cin>>u;
		pre[u]++;
	}
	ll ans=0;
	for (int i = 0; i <= 101; ++i)
	{
		if(pre[i]==0)
		{
			if(abs(i-x)<dif)
			{
				ans=i;
				dif=abs(i-x);
			}
		}
	}
	cout<<ans<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 3612
from sys import exit
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

t=sum(B)-sum(A)
if t==0:
    if A==B: print("Yes")
    else: print("No")
elif t<0: print("No")
else:
    pa=0
    pb=0
    for a,b in zip(A,B):
        if a==b: continue
        if a>b: pb+=(a-b)
        else:
            if (b-a)%2==0: pa+=(b-a)//2
            else:
                pa+=(b-a+1)//2
                pb+=1
    if pa>t or pb>t: print("No")
    else: print("Yes")


Measured memory_bytes: 4600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

int main() {
    string s; getline(cin, s);
    
    for(int i=0; i<s.size(); ++i){
        if(s[i]>='a'&&s[i]<='z'){
            cout << (char)(s[i]-32);
        }else{
            cout << s[i];
        }
    }
    cout << endl;
    
	return 0;
}


Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(){
	
	LL n;
	cin >> n;
	LL a[n];
	
	for( LL i = 0; i < n; i++)
		cin>>a[i];
	
	LL dp[n];
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	
	for( LL i = 2; i < n; i++){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
	
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|


std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

std::vector<int> factor(int n, const std::vector<int>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<int> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}

int main() {
    int N; cin >> N;
    vector<int> exists(1000002, -1);
    set<ll> setwisec;
    bool pairwise = true;
    bool setwise = false;
    vector<int> sieves = sieve(1000001);
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
    }

    REP(i,N){
        // for (auto x : setwisec){
        //     DB2(i,x);
        // }

        for (auto x : setwisec){
            if (A[i] % x != 0) setwisec.erase(x);
        }

        vector<int> D = factor(A[i],sieves);

        REP(j,D.size()){
            ll NowDiv = D[j];
            if (NowDiv == 1) continue;
            //DB2(j, NowDiv);
            if (i == 0){
                setwisec.insert(NowDiv);
            }

            if ((exists[NowDiv] != i) and (exists[NowDiv] != -1)) pairwise = false;
            exists[NowDiv] = i;

        }
    }    
    if (setwisec.empty()) setwise = true;

    if (pairwise){
        puts("pairwise coprime");
    }else if (setwise){
        puts("setwise coprime");
    }else{
        puts("not coprime");
    }
}

Measured memory_bytes: 18836
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin>>n>>t;
  vector<tuple<int,int>> vec1;
  for(int i=0;i<n;i++){
    int p,q;
    cin>>p>>q;
    vec1.push_back(tie(p,q));
  }
  sort(vec1.begin(),vec1.end());
  for(int i=0;i<n;i++){
    if(get<1>(vec1.at(i))<=t){
      cout<<get<0>(vec1.at(i))<<endl;
      return 0;
    }
  }
  cout<<"TLE"<<endl;
  return 0;
}
    

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll h,w;
    cin >> h >> w;
    vs s(h);
    rep(i,h)cin >> s[i];

    ll count;
    rep(i,h){
        rep(j,w){
            count=0;
            if(s[i][j] == '#'){
                cout << s[i][j];
                continue;
            }

            if(j+1 < w)
                    if(s[i][j+1] == '#')count++;
            if(j-1 >= 0)
                if(s[i][j-1] == '#')count++;
            if(i-1 >= 0){
                if(s[i-1][j] == '#')count++;

                if(j-1 >= 0)
                    if(s[i-1][j-1] == '#')count++;
                
                if(j+1 < w)
                    if(s[i-1][j+1] == '#')count++;
            }

            if(i+1 < h){
                if(s[i+1][j] == '#')count++;

                if(j-1 >= 0)
                    if(s[i+1][j-1] == '#')count++;

                 if(j+1 < w)
                    if(s[i+1][j+1] == '#')count++;
            }
            cout << count;
        }
        cout << endl;
    }
    return 0;
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL X, Y; cin >> X >> Y;
	ans = 1;
	while (X*2<=Y) {
		X *= 2;
		ans++;
	}
	
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
 
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
 
void pv(vector<int>&v){
	for(int i = 0;i<v.size();i++){
		if(i)cout<<' ';
		cout<<v[i];
	}
	cout<<endl;
}
#define PP pair<pair<int,int>,pair<int,int>>
 
int bsum=0,N,X,lim = 0;
int b[100010],l[100010],u[100010];
vector<PP>sum;
vector<int>inv;
 
int f(int k){
	if(k>=lim)return true;
	int r = k % X;
	int x = k / X;
	x--;
	rep(i,0,N){
		int diff = 0;
		int tmp = bsum;
		if(inv[i]<=x){
			tmp += sum[x+1].fi.se;
			diff += sum[x+1].se.se;
			if(r<b[i]){
				tmp -= (u[i]-l[i])*b[i];
				diff -= X * u[i];
				diff += r * l[i];
			}else{
				diff -= X * u[i];
				diff += r * u[i];
			}
		}else{
			if(x!=-1)tmp += sum[x].fi.se;
			if(x!=-1)diff += sum[x].se.se;
			if(r<b[i]){
				diff += r * l[i];
			}else{
				tmp += (u[i] - l[i]) * b[i];
				diff += r * u[i];
			}
		}
		if(diff >= tmp)return true;
	}
	return false;
}
 
signed main(){
	IOS();
	cin>>N>>X;
	REP(i,N)cin>>b[i]>>l[i]>>u[i];
	sum.resize(N);
	inv.resize(N);
	REP(i,N){
		lim += b[i];
		bsum += b[i] * l[i];
		sum[i].fi.fi = X*u[i]-(u[i]-l[i])*b[i];
		sum[i].fi.se = b[i] * (u[i] - l[i]);
		sum[i].se.fi = i;
		sum[i].se.se = X * u[i];
	}
	sort(all(sum));
	reverse(all(sum));
	rep(i,0,N){
		inv[sum[i].se.fi] = i;
	}
	rep(i,0,N-1){
		sum[i+1].fi.se += sum[i].fi.se;
		sum[i+1].se.se += sum[i].se.se;
	}
 
	int l = -1, r = INF;
    while(r - l > 1){
        int c = (l + r) / 2;
        if(f(c)) r = c;
        else l = c;
    }
    cout << r << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int cnt[2] = {};
	REP(i, 3) {
		int a;
		scanf("%d", &a);
		if (a == 5) cnt[0]++;
		if (a == 7) cnt[1]++;
	}
	if (cnt[0] == 2 && cnt[1] == 1)
		puts("YES");
	else
		puts("NO");
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

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

    unordered_map<char, ll> counter;
    for (char c : S) {
        if (counter.find(c) == counter.end()) {
            counter[c] = 1;
        } else {
            counter[c]++;
        }
    }

    ll ans = 1;
    for (auto kv : counter) {
        ans = (ans * (kv.second + 1)) % MOD;
    }
    ans--;
    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") printf("Cloudy\n");
    if(s == "Cloudy") printf("Rainy\n");
    if(s == "Rainy") printf("Sunny\n");
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import java.lang.Integer;
import java.lang.StringBuilder;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    long x = in.nextInt();

    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = in.nextInt();
    }

    long cnt = 0;
    for (int i = 0; i < N - 1; i++) {
      if (a[i] + a[i + 1] > x) {
        long sub = a[i] + a[i + 1] - x;
        cnt += sub;
        if (a[i + 1] >= sub) {
          a[i + 1] -= sub;
        } else {
          long tmp = sub - a[i + 1];
          a[i + 1] = 0;
          a[i] -= tmp;
        }
      }
    }

    System.out.println(cnt);
  }
}

Measured memory_bytes: 33080
# 桁数取得関数
def judge_digit(arg_num):
    result = len(str(arg_num))
    return result

N = int(input())
cnt =0

for i in range(1,N+1) :
    aaa = judge_digit(i)
    if aaa %2 ==0 :
        cnt +=0
    else:
        cnt+=1
print(cnt)






Measured memory_bytes: 2940
k = int(input())

cnt = 9
LIM = 10**5+5
gen = [ [1, 2, 3, 4, 5, 6, 7, 8, 9] ]
other = [1,2,3,4,5,6,7,8,9]

while cnt < LIM:
	nw = []
	i = gen[-1]
	for j in i:
		dig = j % 10
		if( dig > 0 ):
			num = j * 10 + (dig-1)
			nw.append(num)
			other.append(num)
			cnt += 1
		num = j * 10 + dig
		nw.append(num)
		other.append(num)
		cnt += 1
		if dig < 9:
			num = j * 10 + (dig + 1)
			nw.append(num)
			other.append(num)
			cnt += 1
	gen.append(nw)
other = sorted(other)
print(other[k-1])


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d,e,k; cin>>a>>b>>c>>d>>e>>k;
	if (e-a<=k) cout << "Yay!\n";
	else cout << ":(\n";
	return 0;
}


Measured memory_bytes: 256
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include <cstring>
using namespace std;
bool flag=false;
int main()
{
    char a[110];
    scanf("%s",a+1);
    int l=strlen(a+1);
    for(int i=1;i<=l;i++)
    {
        if(a[i]=='C')
            flag=true;
        if(a[i]=='F' && flag==true)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if ((a+b) > (c+d)){
    cout << "Left" << endl;
    return 0;
  }else if ((a+b) < (c+d)){
    cout << "Right" << endl;
    return 0;
  }else if ((a+b) == (c+d)){
    cout << "Balanced" << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#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 K, N;
  cin >> K >> N;

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

  int ans = A[0]+K-A[N-1];
  FOR(i, 1, N){
    chmax(ans, A[i]-A[i-1]);
  }

  cout << K-ans << endl;

  return 0;
}

Measured memory_bytes: 1792
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

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

int main(){
  int n;
  cin >> n;
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  ll c[n];
  ll count = 0;
  for(int i=0;i<n;i++){
    c[i] = a[i]-b[i];
    count += c[i];
  }
  if(count < 0){
    cout << -1 << endl;
    return 0;
  }
  sort(c,c+n);
  count = 0;
  int ans = 0;

  for(int i=0;i<n;i++){
    if(c[i] < 0){
      ans++;
      count += c[i];
    }
  }

  reverse(c,c+n);
  int i = 0;
  while(count < 0){
    count += c[i];
    ans++;
    i++;
  }
  cout << ans << endl;
  return 0;
}


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

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

  stack<int> t;
  t.push(s[0]);

  int c = 0;
  for (int i = 1; i < s.size(); i++) {
    if (!t.empty() && t.top() != s[i]) {
      c += 2;
      t.pop();
    } else
      t.push(s[i]);
  }

  cout << c << endl;
}

Measured memory_bytes: 768
import sys
from operator import itemgetter
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(x) for x in input().split()]

cards = [None] * M
for i in range(M):
    B, C = map(int, input().split())
    cards[i] = (B, C)

A = sorted(A)
cards = sorted(cards, key=itemgetter(1), reverse=True)
C = []
for b, c in cards:
    C += [c] * b
    if len(C) > N:
        break
C = C[::-1]

ans = 0
flag = True
for a in A:
    if flag:
        c = C.pop()
        if len(C) == 0:
            flag = False
        if a > c:
            ans += a
            flag = False
        else:
            ans += c
    else:
        ans += a
print(ans)


Measured memory_bytes: 24396
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]

MOD = 2019

p10 = [1] * N
for i in range(1, N):
	p10[i] = (p10[i - 1] * 10) % MOD

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
cnt[0] = 1
for i in range(N):
	cnt[cumsum[i]] += 1

ans = 0
for i in range(MOD):
	ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)


Measured memory_bytes: 30640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    double M=sc.nextInt();
    int[] A=new int[N];
    int counter=0;
    double total=0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      total+=A[i];
    }
    double cap=total/(4.0*M);
    for(int i=0;i<N;i++){
      if(A[i]>=cap) counter++;
    }
    if(counter<M) System.out.println("No");
    else System.out.println("Yes");
  }
}

Measured memory_bytes: 21844
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll a,b;
	cin>>a>>b;
	ll c=0,d=0;
	rep(i,0,a){
		c=c*10+b;
	}
	rep(i,0,b){
		d=d*10+a;
	}
	cout<<max(c,d)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n , d , x;
  scanf("%d %d %d",&n,&d,&x);
  
  int a[n];
  for(int i = 0; i < n;i ++){
  scanf("%d",&a[i]);
  }
  
  int niti , count = x;
  
  for(int i = 0;i < n;i ++){
    niti = 1;
    while(niti<=d){
      count ++;
      niti += a[i];
    }
  }
 printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define read(x) scanf("%d",&x)
typedef long long ll;
typedef double dl;
using namespace std;

const int N=2e5+7;
const int M=1e9+7;
const int INF=0x3f3f3f3f;

ll n,m;

map<ll,int> num;

ll f(ll x){
	return x*x*x*x*x; 
}

void solve(){
	for(ll i=1;i<=4000;i++){
		num[f(i)]=i;
		num[-f(i)]=-i;
	}
	cin>>n;
	for(ll i=1;i<=4000;i++){
		if (num[f(i)-n]){
			cout<<i<<' '<<num[f(i)-n];
			return;	
		}
		if (f(i)==n){
			cout<<i<<' '<<0;
			return;
		}
	}
}

int main(){
//	ios::sync_with_stdio(0);
//  cin.tie(0),cout.tie(0);
//	int T;read(T);
//	for(int i=1;i<=T;i++)
		solve();
}


Measured memory_bytes: 4088
#include <iostream>
#include<unordered_map>
#include<algorithm>

using namespace std;
const int N = 2e5 + 5, M = 1e6 + 10;
int a[N];
int used[M];


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int fl = 1;
    for(int i = 0; i < n; i++)cin >> a[i];
    sort(a, a + n);
    for(int i = 0; i < n; i++)
    {
        fl = 1;
        for(long long j = 1; j * j <= a[i]; j++)
        {
            if(a[i] % j == 0)
            {
                if(abs(used[j]) || abs(used[a[i] / j]))
                {
                    fl = 0;
                    break;
                }
            }
        }
        if(fl)used[a[i]] = 1;
        else used[a[i]] = -1;
    }
    int ans = 0;
    for(int i = 1; i <= 1e6; i++)
    {
        if(used[i] == 1)ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 8304
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
const int maxn=310;
const long long INF=1e18+10;
void chkmin(long long &x,long long y){
	x=x<y?x:y;
}
void chkmax(long long &x,long long y){
	x=x>y?x:y;
}
long long Max(long long x,long long y){
	return x>y?x:y;
}
struct node{
	long long v,r;
}b[maxn];
struct Range{
	long long l,r;
};
bool cmp(const node &A,const node &B){
	return A.r<B.r;
}
bool cmpl(const Range &A,const Range &B){
	return A.l<B.l;
}
long long a[maxn];
long long val[maxn*61][maxn];
int num;
vector<Range> c[maxn*61];
long long d[maxn];
long long getmnv(long long l,long long r){
	if(l>r) return INF;
	int mnv=0;
	for(int j=59;j>=0;j--){
		if((l&(1LL<<j))==(r&(1LL<<j)))
			mnv+=(l>>j)&1;
		else{
			if(l&((1LL<<j)-1))
				mnv++;
			break;
		}
	}
	return mnv;
}
bool equl(long long *A,long long *B,int n){
	for(int i=1;i<=n;i++)
		if(A[i]!=B[i])
			return 0;
	return 1;
}
void Add(int n,int p,long long K){
	if(K<0) return;
	long long Mn=b[1].v-(1<=p);
	for(int i=1;i<=n;i++){
		d[i]=b[i].v-(i<=p);
		if(d[i]<0) return;
		chkmin(Mn,d[i]);
	}
	for(int i=1;i<=n;i++)
		d[i]-=Mn;
	Range st=(Range){Max(Mn-K,0),Mn};
	sort(d+1,d+n+1);
	for(int i=1;i<=num;i++){
		if(equl(d,val[i],n)){
			c[i].push_back(st);
			return;
		}
	}
	num++;
	for(int i=1;i<=n;i++)
		val[num][i]=d[i];
	c[num].push_back(st);
}
int main(){
	int n;
	long long K;
	scanf("%d%lld",&n,&K);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	int nxt;
	long long l,r;
	for(int k=0;k<=60;k++){
		for(int i=1;i<=n;i++){
			b[i].v=a[i]>>k;
			b[i].r=a[i]&((1LL<<k)-1);
		}
		sort(b+1,b+n+1,cmp);
		l=0;
		for(int i=1;i<=n;i=nxt+1,l=r+1){
			nxt=i;
			while(nxt<n&&b[nxt+1].r==b[i].r) nxt++;
			r=b[i].r;
			Add(n,i-1,K-getmnv(l,r)-k);
		}
	}
	long long ans=0;
	for(int i=1;i<=num;i++){
		sort(c[i].begin(),c[i].end(),cmpl);
		l=-2,r=-3;
		for(int j=0;j<(int)c[i].size();j++){
			if(c[i][j].l>r){
				ans=(ans+((r-l+1)%md))%md;
				l=c[i][j].l,r=c[i][j].r;
			}
			else chkmax(r,c[i][j].r);
		}
		ans=(ans+((r-l+1)%md))%md;
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++) cin >> W.at(i);
  int sumL = W.at(0);
  int sumR = 0;
  for (int i = 1; i < N; i++) sumR += W.at(i);
  int diffmin;
  diffmin = abs(sumR - sumL);
  for (int i = 1; i < N-1; i++) {
    sumL += W.at(i);
    sumR -= W.at(i);
    if (diffmin > abs(sumR - sumL)) {
      diffmin = abs(sumR - sumL);
    }
  }
  cout << diffmin << endl;
}

Measured memory_bytes: 3628
/*input
3 2
*/
#include "bits/stdc++.h"
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n>>k;
	if(k==1) cout<<0;
	else cout<<(n-k)<<'\n';
}

Measured memory_bytes: 256
A, B = map(int, input().split())
ans = 0
cnt = 0
def f(arg):
    ans = 0
    if arg < 0:
        return 0
    for pos in range(1, 41):
        # ループする数
        loop = 1 << pos
        # cnt = sum([int((n & v) / v) for n in range(arg+1)])
        cnt = int((arg + 1) / loop) * (loop >> 1)
        cnt += max(0, (arg + 1) % (loop) - (loop >> 1))
        ans += cnt%2 * (loop>>1)
        # print(arg, pos, loop, cnt, ans)
        if loop > arg:
            break
    return ans
print(f(A-1)^f(B))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];

  sort(h.begin(), h.end());

  int ans = INF;
  for (int i = 0; i <= n - k; ++i) {
    ans = min(ans, h[i + k - 1] - h[i]);
  }

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


Measured memory_bytes: 640
N=int(input())
s=[]
t=[]

for i in range(N):
    ss,tt=input().split()
    s.append(ss)
    t.append(int(tt))
X=input();

isok=False
ans=0
for i in range(N):
    if(isok):
        ans+=t[i]
    if(X==s[i]):
        isok=True

print(ans)

Measured memory_bytes: 3064