akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,a,b,c,k;
    cin>>a>>b>>c>>k;
    if(b<=a)
    {
        while(k--)
        {
            b*=2;
            if(b>a)break;
        }
    }
    if(c<=b)
    {
        while(k--)
        {
            c*=2;
            if(c>b)break;
        }
    }
    if(a<b&&b<c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
using namespace std;
const int N=500005;
const int inf=1e9+7;
typedef long long ll;
//------------------------------------------head---------------------------------------------------//
char s[N];
int f[N][3],cnt,a[N],pos[N];
int main()
{
	int n,ans=0;scanf("%d",&n);cnt=0;
	scanf("%s",s+1);rep(i,1,n)a[i]=s[i]-48;pos[0]=-10;
	rep(i,1,n-2)if(a[i] && !a[i+1] && a[i+2])
	{
		++cnt;
		pos[cnt]=i;
		int prev=i;while(prev && a[prev])prev--;
		int nxt=i+2;while(nxt<=n && a[nxt])nxt++;
		//printf("Case 233:%d %d %d\n",prev,i,nxt);
		if(pos[cnt-1]+1==prev)
		{
			if(prev+1==i)
			{
				f[cnt][0]=f[cnt-1][2]+i-prev;
				f[cnt][1]=f[cnt-1][2]+nxt-i-2;
			}
			else
			{
				f[cnt][0]=max(f[cnt][0],f[cnt-1][0]+(i-prev-1));
				f[cnt][0]=max(f[cnt][0],f[cnt-1][1]);
				f[cnt][0]=max(f[cnt][0],f[cnt-1][2]+i-prev);
				f[cnt][1]=max(f[cnt][1],max(max(f[cnt-1][2],f[cnt-1][0])+nxt-i-2,f[cnt-1][1]+(nxt-i-3)));
			}
		}
		else
		{
			f[cnt][0]=max(f[cnt][0],max(f[cnt-1][0],f[cnt-1][1])+(i-prev));
			f[cnt][1]=max(f[cnt][1],max(f[cnt-1][1],f[cnt-1][0])+(nxt-i-2));		
		}
		f[cnt][2]=max(f[cnt-1][0],f[cnt-1][1]);f[cnt][2]=max(f[cnt][2],f[cnt-1][2]);
		f[cnt][0]=max(f[cnt][0],f[cnt][2]);f[cnt][1]=max(f[cnt][1],f[cnt][2]);
		ans=max(ans,f[cnt][0]);ans=max(ans,f[cnt][1]);ans=max(ans,f[cnt][2]);
	}
	//rep(i,2,cnt)printf("%d %d %d\n",f[i][0],f[i][1],pos[i]);
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 6656
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Question1();
            Question2();
        }

        private static void Question1()
        {
            var input = Console.ReadLine();
            char ans = input[0] <= 'Z' ? 'A' : 'a';
            Console.WriteLine(ans);
        }

        private static void Question2()
        {
            var inputA = Console.ReadLine().Split(' ');
            var inputP = Console.ReadLine().Split(' ');

            var N = int.Parse(inputA[0]);
            var K = int.Parse(inputA[1]);

            int[] p = new int[N];

            for (int i = 0; i < N; i++) p[i] = int.Parse(inputP[i]);

            List<int> val = new List<int>();
            foreach (var v in p) val.Add(v);

            val.Sort();
            var sum = 0;
            for (int i = 0; i < K; i++) sum += val[i];

            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 28112
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  int ans = 0;
  for (auto &i : s) {
    if (i == '1') ans++;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3576
from collections import defaultdict
from heapq import heappush, heappop, merge

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

day = defaultdict(list)
for a, b in ab:
    day[a].append(b)

work, ans = [], 0
for i in range(1, m + 1):
    for j in day[i]:
        heappush(work, -j)
    if len(work) > 0:
        ans -= heappop(work)
print(ans)


Measured memory_bytes: 113736
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    if (x==0)
        cout<<1;
    else
        cout<<0;
    return 0;
}


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

int main() {
    ll n;
    cin >> n;
    ll ans = 1e18;
    for(ll i = 1; i*i <= n; ++i)
    {
    	if(n%i != 0) continue;
    	ll j = n/i;
    	ans = min(ans,i+j-2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int N;
pair<plli,plli> dp[314514];
int main(){
	cin>>N;
	vector<ll> hoge;
	rep(i,1<<N){
		ll x;
		cin>>x;
		hoge.pb(x);
	}
	//dp[0]=mp((ll)0,(ll)0);
	ll ans=0;
	for(int i=0;i<(1<<N);i++){
		int cnt=N;
		if(i!=0)dp[i]=mp(mp(hoge[i],i),mp(hoge[0],0));
		else dp[i]=mp(mp(hoge[i],i),mp((ll)0,-1));
		while(cnt--){
			int check=(i>>cnt)%2;
			if(check==1){
				plli a=dp[i-(1<<cnt)].first,b=dp[i-(1<<cnt)].second;
				plli c=dp[i].first,d=dp[i].second;
				vector<plli> ue2;
				ue2.pb(a);ue2.pb(b);
				if(c.second!=a.second&&c.second!=b.second)ue2.pb(c);
				if(d.second!=a.second&&d.second!=b.second)ue2.pb(d);
				sort(all(ue2));
				reverse(all(ue2));
				dp[i]=mp(ue2[0],ue2[1]);
				//cout<<ue2[0].first<<" "<<ue2[1].first<<endl;
			}
		}
		ans=max(ans,dp[i].first.first+dp[i].second.first);
		if(i>0)cout<<ans<<endl;
	}
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i,n){
  ll r;
  cin >> r;
  a[r-1]=i+1;
}
set<ll> s;
s.insert(0);
s.insert(n+1);
rep(i,n){
  auto itr=s.insert(a[i]).first;
  auto itr1=itr;itr1++;
  auto itr2=itr;itr2--;
  ans+=(i+1)*(*itr1-*itr)*(*itr-*itr2);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

int N, l;
vector<int> a;
vector<pair<int, int> > b;

void init()
{
    cin >> N;
    l = 1 << N;
    CINV(a, l);
    b.RS(l);
    rep(i, l) {
        b[i] = MP(a[i], 0);
    }
}

void mer(pair<int, int>& a, pair<int, int> b) {
    int a1 = a.first;
    int a2 = a.second;
    int b1 = b.first;
    int b2 = b.second;
    if (a1 <= b1) {
        a2 = a1;
        a1 = b1;
    } else if (a2 < b1) {
        a2 = b1;
    }
    if (a2 < b2) {
        a2 = b2;
    }
    a.first = a1;
    a.second = a2;
}


void solve()
{
    rep(i, N) {
        rep(j, l) {
            if ((j & (1 << i))) {
                mer(b[j], b[j ^ (1 << i)]);
            }
        }
    }
    int ma = 0;
    reps(i, 1, l) {
        ma = max(ma, b[i].first + b[i].second);
        cout << ma << endl;
    }
}



Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

template <class T>
class WeightedUnionFind {
    vector<int> uni;
    vector<T> weights;
    int n;
public:
    explicit WeightedUnionFind(int n, T SUM_UNITY = 0) :
    uni(static_cast<u32>(n), -1) , n(n), weights(n,  SUM_UNITY){};

    int root(int a) {
        if (uni[a] < 0) return a;
        else {
            int r = root(uni[a]);
            weights[a] += weights[uni[a]];
            return (uni[a] = r);
        }
    }

    bool unite(int a, int b, T w) {
        w += weight(a); w -= weight(b);
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b), w = -w;
        uni[a] += uni[b];
        uni[b] = a;
        weights[b] = w;
        return true;
    }

    int size(int a){
        return -uni[root(a)];
    }

    T weight(T a){
        root(a);
        return weights[a];
    }
    int diff(int x, int y){
        return weight(y) - weight(x);
    }
};



int main() {
    int n, q;
    cin >> n >> q;
    WeightedUnionFind<ll> u(n);
    for (int i = 0; i < q; ++i) {
        int a, x, y;
        ll w;
        scanf("%d", &a);
        if(a) {
            scanf("%d%d", &x, &y);
            if(u.root(x) != u.root(y)){
                printf("?\n");
            }else {
                printf("%d\n", u.diff(x, y));
            }
        }
        else {
            scanf("%d%d%lld", &x, &y, &w);
            u.unite(x, y, w);
        }
    }
    return 0;
}



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

int main() {
    string s;
    cin >> s;
        if((s[0]==s[1]&&s[2]==s[3]) || (s[1]==s[2] && s[0] == s[3]) || (s[1]==s[3] && s[0]==s[2])){
            if(s[0]==s[1] && s[1]==s[2] && s[2]==s[3] && s[3] == s[0]) cout << "No" << endl;
            else cout << "Yes" << endl;
        } else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))

S = [1]*N
for _ in range(M):
    A, B = map(int, input().split())
    if H[A-1]>H[B-1]:
        S[B-1]=0
    elif  H[A-1]<H[B-1]:
        S[A-1]=0
    else:
        S[B-1]=0
        S[A-1]=0
print(sum(S))

Measured memory_bytes: 85072
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[N],delta[N];
ll f[N][5];
//ll ans,f[N][2],s[N],g[N][2],h[N];
int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	/*for (int i=1;i<=n;i++)
	if (a[i]==0) delta[i]=2;
	else delta[i]=a[i]&1;
	for (int i=1;i<=n;i++) g[i][0]=g[i-1][0]+delta[i],s[i]=s[i-1]+a[i];
	ll u=0;
	for (int i=1;i<=n;i++)
	{
		u=min(u,s[i]-g[i][0]);
		f[i][0]=g[i][0]+u;
	}
	for (int i=n;i>=1;i--) g[i][1]=g[i+1][1]+delta[i],s[i]=s[i+1]+a[i];
	u=0;
	for (int i=n;i>=1;i--)
	{
		u=min(u,s[i]-g[i][1]);
		f[i][1]=g[i][1]+u;
	}
	for (int i=1;i<=n;i++) ans+=a[i];
	u=0;
	for (int i=1;i<=n;i++) ans=min(ans,f[i][1]+s[i-1]);
	for (int i=1;i<=n;i++) h[i]=h[i-1]+(a[i]&1^1);
	for (int i=1;i<=n+1;i++)
	{
		ans=min(ans,f[i][1]+u+h[i-1]);
		u=min(u,f[i][0]-h[i]);
	}*/
	for (int i=1;i<=n;i++)
	{
		f[i][0]=f[i-1][0];
		for (int j=1;j<=4;j++)
		f[i][j]=min(f[i][j-1],f[i-1][j]);
		f[i][0]+=a[i],f[i][4]+=a[i];
		f[i][1]+=a[i]==0?2:(a[i]&1);
		f[i][3]+=a[i]==0?2:(a[i]&1);
		f[i][2]+=a[i]&1^1;
	}
	ll ans=f[n][0];for (int i=1;i<=4;i++) ans=min(ans,f[n][i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9216
using System;

namespace noteCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] inputstr = Console.ReadLine().Split(char.Parse(" "));
                int height = int.Parse(inputstr[0]);
                int width = int.Parse(inputstr[1]);
                if(height==0 && width == 0)
                {
                    return;
                }
                for(int cycle = 0; cycle < height; cycle++)
                {
                    bool mode = (cycle % 2 == 0);
                    drawarow(mode, width);
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
        static void drawarow(bool mode,int linenum)
        {
            int temp = 0;
            string[] character;
            character = new string[2];
            if (mode)
            {
                character[0] = "#";
                character[1] = ".";
            }
            else
            {
                character[1] = "#";
                character[0] = ".";
            }
            for(int cycle = 0; cycle < linenum; cycle++)
            {
                Console.Write(character[temp]);
                switch (temp)
                {
                    case 0:
                        temp++;
                        break;
                    case 1:
                        temp--;
                        break;
                }
            }
        }
    }
}



Measured memory_bytes: 15944
s = list(map(int,input()))
s1 = s
ans1,ans2 = 0,0
for i in range(1,len(s)):
  if s[i] != s[i-1]:
    continue
  elif s[i]==0:
    s[i]=1
    ans1+=1
  else:
    s[i]=0
    ans1+=1

if s1[0] == 0:
  s1[0] = 1
else:
  s1[0] = 0
  
for i in range(1,len(s)):
  if s1[i] != s1[i-1]:
    continue
  elif s1[i]==0:
    s1[i]=1
    ans2+=1
  else:
    s1[i]=0
    ans2+=1

print(min(ans1,ans2))

Measured memory_bytes: 3956
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

l=set([1,2,3])
for i in range(2):
    l=l-set([int(input())])
print(int(list(l)[0]))

Measured memory_bytes: 72696
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {  
	ll kazu=1;
	while(1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁


/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll K, N; cin >> K >> N;
	ll dis=0;
	vector<ll> A(N);cin >> A[0];
	for (int i = 1;i < N;i++) {
		cin >> A[i];
		if (A[i] - A[i - 1] > dis) dis = A[i] - A[i - 1];
	}
	if (K - A[N - 1] + A[0] > dis) dis = (K - A[N - 1] + A[0]);
	cout << K - dis << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n);rep(i,n){cin >> a.at(i);}
    priority_queue<ll> pq;
    rep(i,n){pq.push(a[i]);}
    ll cnt=0;
    while(pq.top()+cnt>=n){
        ll top = pq.top();
        pq.pop();
        DEBUG{
            printf("top: %lld, cnt: %lld\n", top, cnt);
        }
        ll sub = (top+cnt-n-1)/(n+1)+1;
        top -= (n+1)*sub;
        cnt += sub;
        pq.push(top);
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> image(2*h);
	for (int i = 0; i < h; i++) cin >> image[i];
	for (int i = 2*h - 1; i >= 0; i--) image[i] = image[(i+2)/2 - 1];
	for (auto&& row : image)
		cout << row << endl;
	return 0;
}


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

int main(void){
	double v_break;
	double x_break;
	double t_break;
	double n;

	while(scanf("%lf", &v_break) != EOF){
		t_break = v_break / 9.8;
		x_break = 4.9 * t_break * t_break;
		n = ceil((x_break + 5) / 5.0);

		printf("%.0f\n", n);
	}

	return 0;
}

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

using namespace std;

int main() {
    unsigned int n, x;
    cin >> n >> x;

    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    long long tot = accumulate(a.begin(), a.end(), 0L);

    if (x == tot) {
        cout << n << endl;
        return 0;
    }

    if (x > tot) {
        cout << n - 1 << endl;
        return 0;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (x >= a[i]) {
            x -= a[i];
            ans++;
        } else {
            break;
        }
    }

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

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = n/2 + n/3 - n/6 + n
    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    private[this] val m = Math.sqrt(n).toInt
    private[this] val sqrtLimit = m/2 + m/3 - m/6 + m

    def isPrime(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) == 0
    def setCmpst(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    private def innerLoop(j: Int, p: Int): Unit = {
      if(j <= top){
        setCmpst(j)
        innerLoop(j + p, p)
      }
    }

    private def loop(i: Int): Unit = {
      if(i <= sqrtLimit){
        if(isPrime(i)){
          val p = 2 * i + 3
          innerLoop((p * p - 3) >>> 1, p)
        }
        loop(i + 1)
      }
    }

    private def next(i: Int): Int =
      if ((i > top) || isPrime(i)) 2 * i + 3 else next(i + 1)

    def exec: Iterator[Int] = {
      loop(0)
      Iterator.single(2) ++ Iterator.single(3) ++ Iterator.iterate(5)(p => next((p - 1) >>> 1)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else if(n==2)println(1)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 67964
#include<bits/stdc++.h>
using namespace std ; 
int main () { 
    ios_base::sync_with_stdio(false);
    long long a,b,c;
    cin>>a>>b>>c;
    long long d = c-a-b;
    if(d > 0 && d*d > 4*a*b) 
        cout<<"Yes"<<"\n";
    else  
        cout<<"No"<<"\n";
    return 0 ; 
}

Measured memory_bytes: 256
(function() {
	var
		S = parseInt(require('fs').readFileSync('/dev/stdin').toString()),
		date = new Date(S * 1000),
		h = date.getUTCHours(),
		m = date.getUTCMinutes(),
		s = date.getUTCSeconds();
	console.log(require('util').format('%d:%d:%d', h, m, s));
}) ();

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    bool height = (0 <= y - r) && (y + r <= H);
    bool width = (0 <= x - r) && (x + r <= W);

    if (height && width) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
long long n;
cin >>n;
  long long a[n];
  int flag=1;
  long long max=1000000000;
  for(long long i=0;i<n;i++){
  cin >>a[i];
    if((a[i]%2)==1){
    flag=2;
      break;
    }
    long long count=0;
    while((a[i]%2)==0){
      count++;
    a[i]=a[i]/2;
    }
    if(max>count){
    max =count;
    }
  }
  if(flag==2){
  cout << "0";
  }
  else{
    cout <<max;
  }
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;

long long int dp[1005][1005];

int main()
{
  ios::sync_with_stdio(false);cin.tie(0);
  int h, w;
  cin >> h >> w;
  char a[h + 5][w + 5];
  for (int i = 1; i <= h; i++)
  {
    for (int j = 1; j <= w; j++)
      cin >> a[i][j];
  }
  for (int i = 0; i <= h; i++)
  {
    for (int j = 0; j <= w; j++)
    {
      if (i == 0 || j == 0)
        dp[i][j] = -1e7;
      else if (i == 1 && j == 1)
        dp[i][j] = 1;
      else
      {
        if (a[i][j] == '.')
        {
          dp[i][j] = max(0 * 1ll, dp[i - 1][j]) + max(0 * 1ll, dp[i][j - 1]);
          dp[i][j] %= 1000000007;
        }
        else
          dp[i][j] = -1e7;
      }
    }
  }
  /*for (int i = 0; i <= h; i++)
  {
    for (int j = 0; j <= w; j++)
    {
      cout << dp[i][j] << " " ;
    }
    cout <<  endl;
  }*/
  cout << dp[h][w] ;
  return 0;
}


Measured memory_bytes: 9088
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

k,n = mi()
a = li()

max_l = 0
for i in range(n-1):
    max_l = max(max_l,a[i+1]-a[i])
max_l = max(max_l,k-a[-1]+a[0])

print(k-max_l)

Measured memory_bytes: 33792
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar)//c + 1):
            for dt in range(0, (maxsugar-ct*c)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

ll N, W, w, v, dp[111][555], www, res;

int main() {
	cin >> N >> W;
	for (int i = 0; i != N; ++i) {
		cin >> w >> v;
		if (!i)www = w;
		for (int j = 100; j != -1; --j) {
			for (int k = 0; k != 401; ++k) {
				dp[j + 1][k + w - www] = max(dp[j + 1][k + w - www], dp[j][k] + v);
			}
		}
	}
	for (int i = 0; i != 101; ++i) {
		for (int j = 0; j != 401; ++j) {
			if (i*www + j <= W)res = max(res, dp[i][j]);
		}
	}
	cout << res << endl;
	return 0;
}


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

queue<pair<int,int>> qu;
char memo[1001][1001];
char memod[1001][1001];
int d[1001][1001]={0};
pair<int,int> cheese[10],now,nextm;
int ans=0,h,w,n;
int x[4] = {1,-1,0,0};
int y[4] = {0,0,1,-1};

int main(){
  int i,j,a,b;
  cin >> h >> w >> n;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      cin >> memo[i][j];
      if(memo[i][j]=='S'){
	cheese[0] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='1'){
	cheese[1] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='2'){
	cheese[2] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='3'){
	cheese[3] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='4'){
	cheese[4] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='5'){
	cheese[5] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='6'){
	cheese[6] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='7'){
	cheese[7] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='8'){
	cheese[8] = make_pair(i,j);
	memo[i][j]='.';
      }
      if(memo[i][j]=='9'){
	cheese[9] = make_pair(i,j);
	memo[i][j]='.';
      }
    }
  }


    for(a=1;a<=h;a++){
    for(b=1;b<=w;b++){
      memod[a][b] = memo[a][b];
      d[a][b] = 0;
      //    cout << memo[a][b];
    }
    //   cout << endl;
  }


  for(j=0;j<n;j++){

        memod[cheese[j].first][cheese[j].second] = 'X';

  
  qu.push(cheese[j]);
  //  while(d[cheese[j+1].first][cheese[j+1].second]==0){
  while(qu.size()){
    now = qu.front();
    //   cout << now.first << now.second << endl;
    qu.pop();
    for(i=0;i<4;i++){
      nextm = make_pair(now.first+x[i],now.second+y[i]);
      //  cout << nextm.first << nextm.second << endl;
      if(nextm.first>=1&&nextm.first<=h&&nextm.second>=1&&nextm.second<=w&&memod[nextm.first][nextm.second]=='.'){
	//	cout << 'A' ;
	memod[nextm.first][nextm.second]='X';
	d[nextm.first][nextm.second] = d[now.first][now.second] + 1;
	qu.push(nextm);
      }
    }
  }

  ans += d[cheese[j+1].first][cheese[j+1].second];
  
  for(a=1;a<=h;a++){
    for(b=1;b<=w;b++){
      memod[a][b] = memo[a][b];
      d[a][b] = 0;
    }
  }
  while(qu.size()){
    qu.pop();
  }

  }

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



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

typedef long long ll;

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// 整数かを判定
bool is_integer( double x ){
  return floor(x)==x;
}

int main()
{
    int N;
    int D;

    cin >> N >> D;

    vector<vector<int>> X(N, vector<int>(D));

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

    int count = 0;

    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            int dis=0;
            for(int k=0; k<D; k++){
                // cout << k << endl;
                dis += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            double dis_sqrt = sqrt(dis);
            // cout << dis << endl;
            if(is_integer(dis_sqrt) == true) count++;
        }
    }

    cout << count << endl;
    return 0;
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    if (s1[0] == s2[2] && s1[1] == s2[1] && s2[0] == s1[2])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <tuple>
#include <functional>

template <class Tp, class Compare>
using priority_queue = std::priority_queue<Tp, std::deque<Tp>, Compare>;

template <class Weight>
struct edge {
  size_t src, dst;
  Weight cost;

  edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  graph(size_t n): std::vector<std::vector<edge<Weight>>>(n) {}

  void connect_with(size_t src, size_t dst, Weight cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
    (*this)[dst].emplace_back(dst, src, cost);
  }
};

template <class Tp>
constexpr Tp inf = Tp(1) << (8*sizeof(Tp)-3);

template <class Weight>
std::vector<Weight> shortest(const graph<Weight> &g, size_t s) {
  // based on Dijkstra algorithm
  std::vector<Weight> res(g.size(), inf<Weight>);
  priority_queue<std::pair<Weight, size_t>, std::greater<>> q;
  res[s] = 0;
  q.emplace(0, s);
  while (!q.empty()) {
    Weight w;
    size_t v;
    std::tie(w, v) = q.top();
    q.pop();
    if (w > res[v]) continue;

    for (const auto& e: g[v]) {
      if (res[e.dst] > w + e.cost) {
        res[e.dst] = w + e.cost;
        q.emplace(res[e.dst], e.dst);
      }
    }
  }
  return res;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  graph<int> g(N);
  for (size_t i = 1; i < N; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a;
    --b;
    g.connect_with(a, b);
  }

  auto d1 = shortest(g, 0);
  auto d2 = shortest(g, N-1);

  int fennec = 0;
  int snuke_ = 0;
  for (size_t i = 0; i < N; ++i)
    ++((d1[i] <= d2[i])? fennec:snuke_);

  puts((fennec > snuke_)? "Fennec":"Snuke");
}


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

using namespace std;

#define long long long
#define INF 1e18
#define MOD (long) (998244353)

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

    map<string, long> d;
    d["AC"] = d["WA"] = d["TLE"] = d["RE"] = 0;

    while (n--) {
        string s;
        cin >> s;
        d[s]++;
    }
    for (auto &s : {"AC", "WA", "TLE", "RE"}) {
        cout << s << " x " << d[s] << endl;
    }
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int R,G,B,N;
long ans;
main()
{
	cin>>R>>G>>B>>N;
	for(int i=0;i*R<=N;i++)for(int j=0;i*R+j*G<=N;j++)
	{
		int k=N-i*R-j*G;
		if(k>=0&&k<=B*N&&k%B==0)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.readline


# 下の桁から貪欲に見ていくと解ける
# 1の位が4以下ならそのまま紙幣で支払うのが得→自身をそのまま答えに採用 (枚数として加算)
# 6以上ならばお釣り狙いのほうが得→自身は0にセットして、上位桁を+1する (枚数として10-自身を加算)
# 5ちょうどのときは、お釣りもそのまま払っても枚数は変わらない。だけど555みたいに、上位桁に+1すると得になる可能性がある。
# 555→15枚, 1000-445→15枚
# つまり5が出たときは更に上位の桁を見て、4以下ならそのまま払うほうが得,5以上なら桁上りのほうが得

# 5ちょうどのときは？ #お釣りもそのまま払っても同じ。だけど上位 お釣り狙いだと上の桁が多くなって支払う金額が増える可能性がある？
# 5ピッタリのときに上位桁に+1すると悪くなる場合が存在する 455 とは 15にってしまう
# 5ピッタリのときはどうするのがよいのか？

N = '00' + read()[:-1]

N = N[::-1]
ans = 0
# agari = 0
# is_pre5 = False
# for n in N:
#     n = int(n) + agari
#     print(n, ans)
#     if is_pre5:
#         if n == 5:
#             ans += n
#             continue

#         if n < 5:
#             # そのまま支払う
#             ans += n
#             agari = 0
#         else:
#             # 桁上り
#             ans += 9 - n
#             agari = 1
#     else:
#         if n == 5:
#             is_pre5 = True
#             ans += n
#             agari = 0
#             # もし5だったら5が終わるまでなめる
#         elif n < 5:
#             ans += n
#             agari = 0
#         else:
#             ans += 10 - n
#             agari = 1
#     if n != 5:
#         is_pre5 = False

i = 0
lo = int(N[i])
while i < len(N) - 1:
    hi = int(N[i + 1])
    # print(hi, lo, i)
    if lo == 5 and hi == 5:
        # 5が連続してた場合
        # 5の最後まで移動(移動の道中は 5+4+4...としていく)
        # 5じゃなくなったhiに対して足し算する必要がある。
        ans += 5
        i += 1
        while i < len(N) - 1 and N[i + 1] == '5':
            ans += 4
            # print(i)
            i += 1
        ans += 4
        # low = N[i]
        hi = int(N[i + 1]) + 1
        # print(hi, lo, i)

        # loが5以外のとき (お釣りが良いか、そのまま払うのが良いか考えるだけ)
    elif lo == 5:
        ans += lo
        if hi < 5:
            pass
        else:
            hi += 1
    elif lo < 5:  # 5が連続しないときもここに入る
        ans += lo
    else:
        ans += 10 - lo
        hi += 1  # 上の桁が繰り上がる
    lo = hi  # 桁を一つずらす
    i += 1


print(ans)


Measured memory_bytes: 5516
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <stdlib.h>
using namespace std;
typedef long long int lld;
typedef long double ld;
pair<lld,lld> arr[222222];
bool tmr(pair<lld,lld> a,pair<lld,lld> b){
	return ((a.second*b.first) + b.first) < ((b.second*a.first) + a.first);
}
bool tmr2(pair<lld,lld> a,pair<lld,lld> b){
	return a.second < b.second;
}
lld dp[33];
vector<pair<lld,lld> > v1,v2;
int main(void){
	for(int e=0;e<33;e++) dp[e] = 2e9;
	int n,t;
	scanf("%d%d",&n,&t);
	for(int e=0;e<n;e++) scanf("%lld%lld",&arr[e].first,&arr[e].second);
	sort(arr,arr+n,tmr);
	for(int e=0;e<n;e++){
		if(arr[e].first!=0) v1.push_back(make_pair(arr[e].first,arr[e].second));
		else v2.push_back(make_pair(arr[e].first,arr[e].second));
	}
	sort(v2.begin(),v2.end(),tmr2);
	lld tot = 0,ans = 0;
	dp[0] = 0;
	for(int e=0;e<v1.size();e++){
		lld dp2[33];
		for(int q=0;q<33;q++) dp2[q] = dp[q];
		for(int q=1;q<33;q++){
			if(dp[q-1]>1e9) break;
			lld tot = dp[q-1];
			tot++;
			if(arr[e].first*tot>2e9) break;
			tot += (arr[e].first*tot+arr[e].second);
			dp2[q] = min(dp2[q],tot);
		}
		for(int q=0;q<33;q++) dp[q] = dp2[q];
	}
	for(int e=0;e<33;e++){
		if(dp[e]>(lld)t) break;
		lld tot = dp[e],val = e;
		for(int p=0;p<v2.size();p++){
			tot++;
			tot += (v2[p].first*tot+v2[p].second);
			if(tot>t) break;
			val++;
		}
		ans = max(ans,val);
	}
	printf("%lld",ans);
	return 0;
}

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

int main(){
  int n,bp,ans=1;cin>>n;
  for(int i=2;i*i<=n;i++){
    bp=i*i;
    while(bp<=n){
      ans=max(ans,bp);
      bp*=i;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
s=input()
l = [
    'AKIHABARA',
    'KIHABARA',
    'AKIHBARA',
    'AKIHABRA',
    'AKIHABAR',
    'KIHBARA',
    'KIHABRA',
    'KIHABAR',
    'AKIHBRA',
    'AKIHBAR',
    'AKIHABR',
    'KIHBRA',
    'KIHBAR',
    'AKIHBR',
    'KIHABR',
    'KIHBR',
]
if s in l:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 79920
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;
 
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}
 
int main() {
	ll A,B;
   	string op;
  	cin >> A >> op >> B;
  	if(op =="+") cout << A+B << endl;
  	else cout << A-B << endl;
}

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

using namespace std;

int main() {
  int n; cin >> n;
  string s;
  cin >> s;
  for(int i=0; i < s.size(); i++) {
    for(int j=0; j < n; j++){
      if(s[i] == 'Z') s[i] = 'A';
      else s[i]++;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
int main()
{ int x,y;
    std::cin>>x>>y;
    for(int i=0;i<=x;i++){
    int a=i;
        int b=x-i;
    if(2*a+4*b==y){
        std::cout<<"Yes"<<std::endl;
        return 0;}
    }
    std::cout<<"No"<<std::endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

  int a,b,c,k;
	cin >> a >> b >> c >> k;

	if(a >= k) cout << k << endl;
	else if(a + b >= k) cout << a << endl;
	else cout << a - (k - a - b) << endl;

  


  // int n, m; cin >> n >> m;
  // int a[600][600];
  // rep(i, n){
  //   rep(j, m){
  //     cin >> a[i][j];
  //   }
  // }
  // dfs(a, n, m);


  return 0;
}

// void dfs(int **a, int n, int m){
//
// }


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n;
  cin >> n;
  while(1){
    if(n%111 == 0) break;
    n++;
  }
  cout << n;
}  


Measured memory_bytes: 3572
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

int main() {
    ll N, M;
    cin >> N >> M;
    graph G(N);
    ll a, b;
    rep(i, M) {
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }
    vector<ll> num(N);
    rep(i, N)num[i] = i;
    ll ans = 0;
    do {
        bool ok = true;
        rep(i, N - 1) {
            bool res = false;
            for (auto x : G[num[i]]) {
                if (x == num[i + 1])res = true;
            }
            if (res == false)ok = false;
        }
        if (ok)ans++;
    } while (next_permutation(num.begin() + 1, num.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 2000000;
const ll MOD = 1000000007;
ll n;
string s;

int main() {
    cin >> n;
    cin >> s;
    ll count = 0;
    for(ll i = 0; i<10; i++){
        string s1 = s;
        ll pos1 = s1.find_first_of(to_string(i));
        if(pos1 != std::string::npos){
            string s2 = s1.substr(pos1+1);
            for(ll j=0; j<10; j++){
                ll pos2 = s2.find_first_of(to_string(j));
                if(pos2 != std::string::npos){
                    string s3 = s2.substr(pos2+1);
                    for(ll k=0; k<10; k++){
                        ll pos3 = s3.find_first_of(to_string(k));
                        if(pos3 != std::string::npos){
                            count++;
                        }
                    }
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
l = [[False] * 13 for i in range(4)]
shcd = ["S", "H", "C", "D"]
for i in range(n):
    x, y = input().split()
    l[shcd.index(x)][int(y) - 1] = True
for i in range(4):
    for j in range(13):
        if not l[i][j]:
            print(shcd[i], j + 1)


Measured memory_bytes: 5604
#include<stdio.h>
#include<math.h>

int isprime(int x){
  if(x == 2){
    return 1;
  }
  if(x < 2 ||x%2==0){
    return 0;
  }
  int i = 3;
  while(i <= sqrt(x)){
    if(x%i==0){
      return 0;
    }

    i = i + 2;
  }

 return 1;
}
int main(void){
  int a[10000];
  int n,i,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int j=0;j<n;j++){
    int c=a[j];
    if(isprime(c)==1){count++;}
  }
  printf("%d\n",count);
  return 0;

}



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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int n;
    cin >> n;
    int F[50];
    F[0] = F[1] = 1;
    for (int i = 2; i <= n; i++) {
        F[i] = F[i - 1] + F[i - 2];
    }
    cout << F[n] << endl;

    return 0;
}



Measured memory_bytes: 3152
let N = stdin.ReadLine() |> int
let S =
    [|1..N|]
    |> Array.map (fun _ -> stdin.ReadLine())

S
|> Array.scan (fun (ac,wa,tle,re) item ->
    match item with
    | "AC" -> (ac+1,wa,tle,re)
    | "WA" -> (ac,wa+1,tle,re)
    | "RE" -> (ac,wa,tle,re+1)
    | "TLE" -> (ac,wa,tle+1,re)) (0,0,0,0)
|> ((fun x -> x.[N]) >> (fun (ac,wa,tle,re) -> printfn "AC x %d\nWA x %d\nTLE x %d\nRE x %d" ac wa tle re))

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

int main(){
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy";
    }else if(s == "Cloudy"){
        cout << "Rainy";
    }else{
        cout << "Sunny";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, m;
  scanf("%lld", &n);
  if(n == 2) {
    printf("-1");
    return 0;
  }
  char s[n][n + 10];
  char t4[4][5] = {"aacd", "bbcd", "cdaa", "cdbb"}, t3[3][4] = {"abb", "a.c", "ddc"};
  char t5[5][6] = {"wxyy.", "wx..z", "abb.z", "a.cxx", "ddcyy"};
  for(i = 0; i < n; ++i) {
    for(j = 0; j < n; ++j) s[i][j] = '.';
    s[i][n] = 0;
  }
  if(n == 3) {
    for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) s[i][j] = t3[i][j];
  } else if(n == 6) {
    for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) if(i / 3 == j / 3) s[i][j] = t3[i % 3][j % 3];
  } else if(n == 7) {
    for(i = 0; i < 6; ++i) for(j = 0; j < 6; ++j) if(i / 3 == j / 3) s[i][j] = t3[i % 3][j % 3];
    for(i = 0; i < 6; i += 2) s[6][i] = s[6][i + 1] = s[i][6] = s[i + 1][6] = 'p' + i;
  } else if(n == 11) {
    for(i = 0; i < 9; ++i) for(j = 0; j < 9; ++j) if(i / 3 == j / 3) s[i + 2][j + 2] = t3[i % 3][j % 3];
    for(i = 1; i < 11; i += 2) {
      m = (i & 2) >> 1;
      s[m][i] = s[m][i + 1] = s[i][m] = s[i + 1][m] = 'z';
    }
  } else {
    m = n & 3;
    m *= 5;
    k = n - m;
    for(i = 0; i < m; ++i) for(j = 0; j < m; ++j) if(i / 5 == j / 5) s[i][j] = t5[i % 5][j % 5]; 
    for(i = 0; i < k; ++i) for(j = 0; j < k; ++j) if(i / 4 == j / 4) s[i + m][j + m] = t4[i & 3][j & 3];
  }
  for(i = 0; i < n; ++i) printf("%s\n", s[i]);
  return 0;
}

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

int main(){
  int N,cnt=0;
  cin >> N;
  for(int i=1;i<=N;i++){
    int a;
    cin >> a;
    if(a!=i)
      cnt++;
  }
  if(cnt<3)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()
B = LI()

if N == 1:
    if A[0] == B[0]:
        print('No')
    else:
        print('Yes')
        print(B[0])
    exit()

def place(i,j):
    if 0 <= j-i<= N-1:
        return j-i
    else:
        return N+j-i


C = set()
for i in range(N):
    C.add(i)

de = defaultdict(list)
for i in range(N):
    de[B[i]].append(i)

a = 0
b = 0
cu = [0]*(N+1)
for i in range(1,N):
    if A[i-1] == A[i]:
        b += 1
    else:
        b = i-1
        if len(de[A[a]]) == 0:
            a = i
            continue
        else:
            c = de[A[a]][0]
            d = de[A[a]][-1]
            if d-a >= 0:
                left = max(0,min(c-a,d-b))
                right = d-a
                cu[left] += 1
                cu[right+1] -= 1
            if c < b:
                left = N+c-b
                right = min(N-1,max(N+d-b,N+c-a))
                cu[left] += 1
                cu[right+1] -= 1
            a = i

if len(de[A[a]]) == 0:
    a = i
else:
    c = de[A[a]][0]
    d = de[A[a]][-1]
    if d-a >= 0:
        left = max(0,min(c-a,d-b))
        right = d-a
        cu[left] += 1
        cu[right+1] -= 1
    if c < b:
        left = N+c-b
        right = min(N-1,max(N+d-b,N+c-a))
        cu[left] += 1
        cu[right+1] -= 1
    a = i


cumu = [0]*N
for i in range(N):
    cumu[i] = cumu[i-1]+cu[i]
#print(cumu)
for k in range(N):
    if cumu[k] <= 0:
        print('Yes')
        ans1 = [B[i+k] for i in range(N-k)]
        ans2 = [B[i-(N-k)] for i in range(N-k,N)]
        ans1.extend(ans2)
        print(*ans1)
        exit()

print('No')

Measured memory_bytes: 169148