akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main()
{
  ll n,l; cin>>n>>l;
  string s[n];
  rep(i, n) {
    cin >> s[i];
  }
  sort(s, s+n);

  string ans="";
  rep(i,n){
    ans += s[i];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)
#define umap unordered_map

int main()
{
    long t = 1;
    //cin >> t;

    while (t--) {
        long k, n;
        cin >> n >> k;

        multiset<long> s;
        for (long i = 0; i < n; i++) {
            long x;
            cin >> x;
            s.insert(x);
        }
        long count = 0;
        long total = 0;
        for (auto &x : s) {
            total += x;
            if (++count == k) break;
        }
        printf("%lld\n", total);
    }
}


Measured memory_bytes: 3676
n,k=map(int,input().split())
a=[k+i for i in range(n)]
b=[n+i for i in a]
c=[n+i for i in b]
if sum(a)+sum(b)>sum(c):print(-1);exit()
i=n-1
j=b.index(2*n)
print(k+n-1,2*n,k+3*n-1)
bs={2*n}
for k in range(n-1-(n%2==0),0,-1):
  i-=2
  j+=1
  if i<0:i=n+i
  if j==n:j=0
  if i==n-1:
    i-=1
    j+=1
  bs.add(b[j])
  print(a[i],b[j],c[k-n%2])
if n%2==0:
  for i in b:
    if not i in bs:bb=i
  print(a[0],bb,c[0])

Measured memory_bytes: 23160
from collections import deque
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
table = [[] for i in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  table[a].append(b)
  table[b].append(a)
task = [0]*N
point = [-1]*N
point[0] = 0
for i in range(Q):
  p,x = map(int, input().split())
  p -= 1
  task[p] += x
H = deque()
H.append(0)

while H:
  p = H.popleft()
  point[p] += task[p]
  for np in table[p]:
    if point[np] == -1:
      H.append(np)
      point[np] = point[p]

print(" ".join(map(str, point)))


Measured memory_bytes: 73104
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

typedef pair<int, int>P;

int dst[30][30];

int R, C;
char maze[30][30];
int BFS(int Sx,int Sy,int Gx,int Gy);
void debug();


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	cin >> R >> C;

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

	int ans = 0;

	for (int Sx = 0; Sx < C; Sx++) {
		for (int Sy = 0; Sy < R; Sy++) {

			if (maze[Sy][Sx] == '#') {
				continue;
			}

			for (int Gx = 0; Gx <C; Gx++) {
				for (int Gy = 0; Gy < R; Gy++) {

					if (maze[Gy][Gx] == '#') {
						continue;
					}

					int bfs = BFS(Sx, Sy, Gx, Gy);
					ans = max(ans, bfs);


				}




			}
		}
	}


	cout << ans;


}


int BFS(int Sx,int Sy,int Gx,int Gy) {
	queue<P> que;

	que.push(P(Sy, Sx));
	for (int i = 0; i < R; i++)
		for (int j = 0; j < C; j++)dst[i][j] = c_YET;
	dst[Sy][Sx] = 0;

	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == Gy && p.second == Gx)break;

		for (int i = 0; i < 4; i++) {
			int ny = p.first + DY[i];
			int nx = p.second + DX[i];

			if (ny >= 0 && ny < R&&nx >= 0 && nx < C&&maze[ny][nx] != '#' &&dst[ny][nx] == c_YET) {
				que.push(P(ny, nx));
				dst[ny][nx] = dst[p.first][p.second] + 1;
				//debug();
			}
		}
	}
	return dst[Gy][Gx];
}

void debug() {
	printf("\n");
	for (int i = 0; i < R; i++) {
		printf("\n");
		for (int j = 0; j < C; j++)
			printf("%d  ", dst[i][j]);
	}

}



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

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

#define N (1<<18)
template<class T>
struct RMQ{
	pair<T,int>dat[2*N];
	T inf;
	function<pair<T,int>(pair<T,int>,pair<T,int>)>merge;
	RMQ(T Inf,function<pair<T,int>(pair<T,int>,pair<T,int>)>Merge){
		inf=Inf;merge=Merge;
		rep(i,2*N-1){
			dat[i].first=inf;
			if(i>=N-1)dat[i].second=i-N+1;
		}
	}
	void update(int k,T x){
		k+=N-1;
		dat[k].first=x;
		while(k){
			k=(k-1)/2;
			dat[k]=merge(dat[k*2+1],dat[k*2+2]);
		}
	}
	pair<T,int>query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l||r<=a)return make_pair(inf,-1);
		if(a<=l&&r<=b)return dat[k];
		auto lb=query(a,b,k*2+1,l,(l+r)/2);
		auto rb=query(a,b,k*2+2,(l+r)/2,r);
		return merge(lb,rb);
	}
	T getValue(int a,int b){
		return query(a,b).first;
	}
	int getIndex(int a,int b){
		return query(a,b).second;
	}
};
template<class T>
pair<T,int>RangeMax(pair<T,int>a,pair<T,int>b){
	return a.first>=b.first?a:b;
}
template<class T>
pair<T,int>RangeMin(pair<T,int>a,pair<T,int>b){
	return a.first<=b.first?a:b;
}


RMQ<ll>dp(INFL,RangeMin<ll>);
vector<P>E[200000];

int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		int l,r,c;scanf("%d%d%d",&l,&r,&c);l--;r--;
		E[r].push_back(P(l,c));
	}
	dp.update(0,0);
	for(int i=1;i<n;i++){
		ll C=INFL;
		for(auto u:E[i]){
			ll Min=dp.getValue(u.first,i);
			if(Min!=INFL){
				Min+=u.second;
				C=min(C,Min);
			}
		}
		dp.update(i,C);
	}
	ll res=dp.getValue(n-1,n);
	if(res==INFL)puts("-1");
	else cout<<res<<endl;
}

Measured memory_bytes: 16128
import sys
readline = sys.stdin.readline

MOD = 10**9+7
N, K = map(int, readline().split())
A = list(map(int, readline().split()))
posi = [(a, 0) for a in A if a >= 0]
nega = [(-a, 1) for a in A if a < 0]
B = posi + nega
B.sort(reverse = True)

if N == K:
    ans = 1
    for i in range(K):
        ans = (ans*A[i]) % MOD  
    print(ans)
elif N == len(nega):
    if K & 1:
        A.sort(reverse = True)
    else:
        A.sort()
    ans = 1
    for i in range(K):
        ans = (ans*A[i]) % MOD  
    print(ans)
else:
    cnt = 0
    for i in range(K):
        _, s = B[i]
        cnt ^= s
    
    res, _ = map(list, zip(*B[:K]))
    if cnt:
        pf, nf, ps, ns = None, None, 0, 0
        for i in range(K):
            b, s = B[i]
            if s:
                nf = b
            else:
                pf = b
        
        for i in range(K, N):
            b, s = B[i]
            if s:
                ns = b
                break
        for i in range(K, N):
            b, s = B[i]
            if not s:
                ps = b
                break
        
        if pf is None:
            res.remove(nf)
            res.append(ps)
        elif nf is None:
            res.remove(pf)
            res.append(ns)
        elif ns*nf >= pf*ps:
            res.remove(pf)
            res.append(ns)
        else:
            res.remove(nf)
            res.append(ps)
        
    ans = 1
    for r in res:
        ans = (ans*r) % MOD
        
    print(ans)
        
    

Measured memory_bytes: 129224
#include<bits/stdc++.h>
#define MN 100005
int n,a[MN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	std::sort(a+1,a+1+n);
	for(int i=n,j=1;i>=1;i--,j++)
		if(j+1>a[i-1]) {
			bool ans=0,now=0;
			for(int k=i-1;k;k--)
			{
				if(a[k]!=j) break;
				now^=1;
			}
			ans|=(a[i]-j)&1;
			ans|=now;
			puts(ans?"First":"Second");
			return 0;
		}
}

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;

int N, A, B;
int h[100000];

bool enough(int count) {
	// cout << "enough(" << count << ") : " << endl;
	long long need = 0;
	int buf = 0;
	for (int i = 0; i < N; i++) {
		buf = h[i] - count * B;
		if (buf > 0) {
			need += (buf + (A - B - 1)) / (A - B);
		}
	}
	if (need <= count) return true;
	else return false;
}

int bi_search(int max) {
	int lb = 0, ub = max;
	while (ub > lb) {
		int mid = (lb + ub) / 2;
		if (enough(mid)) ub = mid;
		else lb = mid + 1;
	}
	return ub;
}

int main() {
	cin >> N >> A >> B;
	int max = 0;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		if (max < h[i]) max = h[i];
	}
	cout << bi_search((max + B) / B) << endl;
}

Measured memory_bytes: 640
/// b.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static vi g[1 << 20];
    static int answer[1 << 20];
    int n,m;
    IOS;
    fi>>n>>m;
    while (m --)
    {
        int a,b;
        fi>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int q;
    fi>>q;
    static int D[1 << 20][20];
    static int color[1 << 20];
    vector < vi > qq;
    priority_queue < pair < int , pii > > Q;
    for (int i = 1;i <= q;++i)
    {
        int a,b,c;
        fi>>a>>b>>c;
        color[i] = c;
        D[a][b] = i;
        Q.push(mp(i,mp(a,b)));
    }
    while (!Q.empty())
    {
        pii node = Q.top().y;
        int how = Q.top().x;
        Q.pop();
        if (D[node.x][node.y] != how || !node.y)
            continue;
        for (auto it : g[node.x])
            if (D[it][node.y - 1] < how)
                D[it][node.y - 1] = how,Q.push(mp(how,mp(it,node.y - 1)));
    }
    for (int i = 1;i <= n;++i)
    {
        int t = 0;
        for (int k = 0;k < 15;++k)
            smax(t,D[i][k]);
        answer[i] = color[t];
    }
    for (int i = 1;i <= n;++i)
        fo << answer[i] << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 46060
S = input() #ここで標準入力
rev = S[::-1]

l = int(len(S)/2)
front = S[0:l]
back = rev[0:l]

cnt = 0
moji = 0

for s in front:
    if front[cnt] == back[cnt]:
        moji += 1
    cnt += 1

ans = l - moji
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int a, b, u0, u1, ue, sum;
    scanf("%d %d %d %d %d", &a, &b, &u0, &u1, &ue);
    sum = (a < 0) ? (a*u0* -1)+(u1)+(b*ue) : (b-a) * ue;
    printf("%d\n", sum);
    return 0;
}



Measured memory_bytes: 2736
#include<iostream>
#include<vector>
#include <algorithm>

using namespace std;

int main(void)
{
  int N;
  
  cin>>N;
  
  vector<int> pos(N);
  
  for(int i=0;i<N;i++)
  {
    cin>>pos[i];
  }
  
  sort(pos.begin(),pos.end());
  
  int max,min,ans;
  
  max=pos[N-1];
  min=pos[0];
  
  ans=max-min;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n - i + 1):
        k = n - (i + j)
        if 10000 * i + 5000 * j + 1000 * k == y:
            print(i, j, k)
            exit()

print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// import here

int main(){
    LL n, k;
    cin >> n >> k;
    LL cnt = (n-1)*(n-2)/2;
    if(k > cnt){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<LL,LL>> edge;
    for(LL i = 1; i < n; ++i){
        edge.emplace_back(0, i);
    }
    for(LL i = 1; i < n; ++i){
        for(LL j = i+1; j < n; ++j){
            if(cnt == k) break;
            --cnt;
            edge.emplace_back(i, j);
        }
    }
    cout << edge.size() << endl;
    for(auto p: edge){
        cout << p.first+1 << " " << p.second+1 << endl;
    }
    return 0;
}



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

using namespace std;

int main(){

	while(1){
		string str;
		int serve=0;
		for(int i = 0; i < 3; i++){
			cin>>str;
			if(str=="0")
				return 0;
			int A=0;
			int B=0;
			for(int i = 1; i < str.size(); i++){
				if(str[i]=='A'){
					A++;
				}
				else
					B++;
			}
			if(A>B)
				A++;
			else
				B++;
			cout<<A<<" "<<B<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();
  string s,s2;
  cin>>s>>s2;
  int n1 = s.length(),n2 = s2.length();

  ll dp[n1+1][n2+1];
  for(int i = 0;i<=n1;i++)
  {
    for(int j = 0;j<=n2;j++)
    {
      if(i==0 || j==0)
        dp[i][j] = 0;
      else if(s[i-1]==s2[j-1])
        dp[i][j] = dp[i-1][j-1]+1;
      else 
        dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
    }
  }
  int i = n1,j = n2;
  string ans = "";
  while(i!=0 && j!=0)
  {
    if(s[i-1]==s2[j-1])
    {
      ans+=s[i-1];
      i--;j--;
    }
    else if(dp[i-1][j]>=dp[i][j-1])i--;
    else j--;
  }
  reverse(all(ans));
  cout<<ans<<endl;

  return 0;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n,num,i;
	cin>>n;
	set<int> s;
	for(i=0;i<n;++i)
	{
		cin>>num;s.insert(num);
	}
	if(s.size()==n)cout<<"YES";
	else cout<<"NO";
	return 0;
}


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

typedef long long ll;

set<ll> s;

ll k;

int main(){
    cin >> k;
    for(int i = 1;i < 10;i++){
        s.insert(i);
    }
    while(k--){
        auto it = s.begin();
        if(k == 0){
            cout << *it << endl;
        }else{
            ll num = *it;
            int digit = (*it) % 10;
            s.erase(it);
            for(int i = 0;i < 10;i++){
                if(abs(i - digit) <= 1){
                    s.insert(num * 10 + i);        
                }
            }
        }
    }
    return 0;
}


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



int main(){
  string N;
  cin >> N;
  if(N=="SSS"){
    cout <<0 << endl;
  }
  else if(N=="RSS"||N=="SRS"||N=="SSR"||N=="RSR"){
    cout <<1<<endl;
  }
  else if(N=="RRS"||N=="SRR"){
    cout << 2 << endl;
  }
  else{
    cout << 3 << endl;
  }
  
  
 
}



Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b=map(int,input().split())
ab=a*b
if ab%2==1:
    print("Odd")
else:
    print("Even")


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int x;
     cin>>x;
     cout<<(x<1200 ? "ABC" : "ARC")<<endl;
     time();
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int zero = 0, one = 0;
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='0') zero++;
        else one++;
    }
    cout << zero+one-abs(zero-one) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
int dp[110][5];

string s;
int k, n;
ll dfs(int pos, int num, bool lim){
	if(num>k)return 0;
	if(pos>=n) return num==k;
	if(!lim&&dp[pos][num]!=-1)return dp[pos][num];
	ll ret = 0;
	int up = lim?s[pos]-'0':9;
	for(int i=0; i<=up; ++i){
		ret += dfs(pos+1, num+(i!=0), lim&&(i==up)); 
	} 
	if(!lim)dp[pos][num]=ret;
	return ret;
}
int main()
{
	cin >> s >> k;
	memset(dp, -1, sizeof(dp));
	n=s.size();
	cout << dfs(0, 0, 1)<<"\n";
} 

Measured memory_bytes: 256
// Problem Code: abc176_e

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int bomber(int H, int W, int M, vector<int>& h, vector<int>& w) {
	int max_bombs, max_row, max_col;
	set<pair<int, int>> seen;
	vector<int> candidate_rows, candidate_cols, rows(H), cols(W);
	
	for (int i = 0; i < M; i++) {
		rows[h[i]]++;
		cols[w[i]]++;
		seen.insert({h[i], w[i]});
	}
	
	max_row = *max_element(rows.begin(), rows.end());
	max_col = *max_element(cols.begin(), cols.end());
	max_bombs = max_row + max_col - 1;
	
	for (int i = 0; i < H; i++)
		if (rows[i] == max_row)
			candidate_rows.push_back(i);
	for (int i = 0; i < W; i++)
		if (cols[i] == max_col)
			candidate_cols.push_back(i);
	
	for (int& row: candidate_rows)
		for (int& col: candidate_cols)
			if (!seen.count({row, col}))
				return 1 + max_bombs;
	
	return max_bombs;
}

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	vector<int> h(M), w(M);
	for (int i = 0; i < M; i++) {
		cin >> h[i] >> w[i];
		h[i]--, w[i]--;
	}
	cout << bomber(H, W, M, h, w);
	return 0;
}

Measured memory_bytes: 26152
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int h,w,d;
    cin >> h >> w >> d;
    std::vector<pii> place(h * w + 1,pii(0,0));
    std::vector<int> sum(h * w + 1, 0);

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int temp;
            cin >> temp;
            place[temp] = pii(i,j);
        }
    }

    int q;
    cin >> q;
    for(int i = 1; i <= d; i++){
        int now = i;
        while(now + d <= h * w){
            sum[now + d] = abs(place[now + d].first - place[now].first) + abs(place[now + d].second - place[now].second) + sum[now];
            now += d;
        }
    }    
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,string> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    rep(i,n&&cin>>arr[i])
    {
        sum+=arr[i];
    }
    int mac=abs(sum-m);
    sort(arr,arr+n);
    cout<<n+(mac/arr[0]);
go;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
D=[0]*(K+1)
D[K]=1
mod=10**9+7
for i in range(K,0,-1):
  D[i]=pow(K//i,N,mod)
  for j in range(2*i,K+1,i):
    D[i]=(D[i]-D[j])%mod

c=0
for i in range(len(D)):
  c+=D[i]*i
print(c%mod)

Measured memory_bytes: 11272
A,B,C = map(int, input().split())
K = int(input())
D = B
E = C
i1 = 0
i2 = 0
while(D<=A):
    D = D*2
    i1 +=1
while(E<=D):
    E = E*2
    i2 +=1
if K >= i1+i2:
    print("Yes")
else:
    print("No") 

Measured memory_bytes: 61624
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type rs []rune

func (a rs) Len() int           { return len(a) }
func (a rs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a rs) Less(i, j int) bool { return a[i] < a[j] }

func main() {
	n := getInt()
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		s := rs(getString())
		sort.Sort(s)
		m[string(s)]++
	}

	ans := 0
	for _, v := range m {
		ans += v * (v - 1) / 2
	}

	fmt.Println(ans)
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i,n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i--)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define mem(x,n) memset(x,n,sizeof(x))
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
     fast
     ll x;
     cin>>x;
     if(x==0)
     cout<<1;
     else
     cout<<0;
}

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


int brack(int n){
	int x = 100000;
	int y = 0;
	for (int i = 0; i < n; i++){
		x *= 1.05;
		y = x % 1000;
		if (y != 0){
			x -= y;
			x += 1000;
		}
	}
	return x;
}


int main(){
	int n;
	cin >> n;
	cout << brack(n) << endl;

	return 0;
}


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

a.sort()
for x in a[:]:
    a.append(x + k)

len_min = k
for i in range(n):
    l = a[n + i - 1] - a[i]
    if l < len_min:
        len_min = l

print(len_min)

Measured memory_bytes: 26444
#include <iostream>

using namespace std;

// a > b
static long long gcd(long long a, long long b) {
  return !b ? a : gcd(b, a % b);
}

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

int main() {
  long long a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main()
{
	int N,i;
	scanf("%d",&N);

	if(N % 2 == 0)
		i = N / 2;

	else if(N == 1)
		i = N;

	else
		i = (N / 2) + 1;

	printf("%d",i);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

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

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

  string s;
  cin >> s;

  int c0 = 0, c1 = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == '0') ++c0;
    else ++c1;
  }

  int ans = min(c0, c1) * 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    
    int min,max;
    min=10000;
    max=-1;
    int kari;
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        
        scanf("%d",&kari);
        if(min>kari)min=kari;
        if(max<kari)max=kari;
    }
    printf("%d",max-min);
    return 0;
}


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

int main() {
    int m, n; cin>>m>>n;
    int len; cin>>len;
    int sx, sy; cin>>sx>>sy;
    string s, t; cin>>s>>t;
    int tx = sx, ty = sy;
    for(int i=0; i<len; i++) {
        if(s[i] == 'D') {
            tx++;
            if(tx > m) {
                cout<<"NO"<<endl;
                goto A;
            }
        }
        if(t[i] == 'U') {
            if(tx != 1) tx--;
        }
    }
    tx = sx;
    for(int i=0; i<len; i++) {
        if(s[i] == 'U') {
            tx--;
            if(tx < 1) {
                cout<<"NO"<<endl;
                goto A;
            }
        }
        if(t[i] == 'D') {
            if(tx != m) tx++;
        }
    }
    ty = sy;
    for(int i=0; i<len; i++) {
        if(s[i] == 'L') {
            ty--;
            if(ty < 1) {
                cout<<"NO"<<endl;
                goto A;
            }
        }
        if(t[i] == 'R') {
            if(ty != n) ty++;
        }
    }
    ty = sy;
    for(int i=0; i<len; i++) {
        if(s[i] == 'R') {
            ty++;
            if(ty > n) {
                cout<<"NO"<<endl;
                goto A;
            }
        }
        if(t[i] == 'L') {
            if(ty != 1) ty--;
        }
    }
    cout<<"YES"<<endl;
    A:;
    return 0;
}


Measured memory_bytes: 776
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main()
{
    ll h,w,k;
    cin >> h >> w >> k;
    vector<vector<ll>> dp(h+1,vector<ll>(w));
    dp[0][0]=1;
    rep(i,h){
        for(ll j=0;j<(1<<(w-1));j++){
            bool ok=true;
            for(ll s=0;s<w-2;s++){
                if((j>>s)%2==1 && (j>>(s+1))%2==1){
                    ok=false;
                    break;
                }
            }
            if(!ok) continue;
            for(ll s=0;s<w;s++){
                if(s<w-1 && (j>>s)%2==1){
                    dp[i+1][s+1]+=dp[i][s];
                    dp[i+1][s+1]%=mod;
                    continue;
                }
                if(s>0 && (j>>(s-1))%2==1){
                    dp[i+1][s-1]+=dp[i][s];
                    dp[i+1][s-1]%=mod;
                    continue;
                }
                dp[i+1][s]+=dp[i][s];
                dp[i+1][s]%=mod;
            }
        }
    }
    cout << dp[h][k-1] << endl;
    return 0;
} 

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

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

int main() {
  int N;
  cin >> N;
  int max = 0;
  int ans = 0;
  int h;
  for(int i = 0; i < N; ++i) {
    cin >> h;
    if(chmax(max, h)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
    ll X,Y,A,B,C,sum=0;
    cin >> X >> Y >> A >> B >> C;   

    priority_queue<int> queX,queY,queAll;
    for (int i = 0; i < A; i++) {
        ll in; cin >> in;
        queX.push(in);
    }
    for (int i = 0; i < B; i++) {
        ll in; cin >> in;
        queY.push(in);
    }
    for (int i = 0; i < C; i++) {
        ll in; cin >> in;
        queAll.push(in);
    }
    for (int i = 0; i < X; i++) {
        queAll.push(queX.top());
        queX.pop();
    }
    for (int i = 0; i < Y; i++) {
        queAll.push(queY.top());
        queY.pop();
    }
    for (int i = 0; i < X+Y; i++) {
        sum+=queAll.top();
        queAll.pop();
    }

    cout << sum << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    int ans=0;
    map<int,int>mp;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        mp[a]++;
        if(a>100000){
            ans++;
        }
    }
    for(int i=1;i<100001;i++){
        if(mp.count(i)){
            if(mp[i]>=i){
                ans+=mp[i]-i;
            }
            else{
                ans+=mp[i];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7916
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String s = sc.next();

        if (s.charAt(0) == s.charAt(1) && s.charAt(0) == s.charAt(2)) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }



    }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
 
ll maxll(ll a , ll b ){
    return a > b ? a : b;
}
 
ll minll(ll a , ll b){
    return a > b ? b : a;
}

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }


// To count Number of ones in a binary number
// int count_one(int x){
//     x = (x & (0x55555555)) + ((x >> 1) & (0x55555555));
//     x = (x & (0x33333333)) + ((x >> 2) & (0x33333333));
//     x = (x & (0x0f0f0f0f)) + ((x >> 4) & (0x0f0f0f0f));
//     x = (x & (0x00ff00ff)) + ((x >> 8) & (0x00ff00ff));
//     x = (x & (0x0000ffff)) + ((x >> 16) & (0x0000ffff));
//     // cout << x << endl;
//     return x;
// }

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

// void print_vi(vi a){
//     for (int i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }

// Best algo to find maximum sum subarray (contiguous)
// ll kadane (vl a){
//     ll curr = 0 , maxi = 0;
//     f(i , 0 , a.size()){
//         curr = max(a[i] , curr + a[i]);
//         maxi = max(maxi , curr);
//     }
//     return maxi;
// }

void solve(){
    
    int n;
    cin >> n;
    vi a(n);
    ll sum = 0;
    map <int , int> map1;
    f( i , 0 , n){
        cin >> a[i];
        map1[a[i]]++;
        sum += a[i];
    }

    int q;
    cin >> q;
    int c , d , temp;
    while(q--){
        cin >> c >> d;
        temp = map1[c];
        map1[c] = 0;
        map1[d] += temp;
        sum += temp*(d-c);
        cout << sum << endl;
    }
    return;

}

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

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

Measured memory_bytes: 7952
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,m,u,v,c,vis[100007],val[100007],L=1,R=1e9-1;
int p[100007];
vector < pair<int,int> > edge[100007];
void out(){
	cout<<0;
	exit(0);
}
void dfs(int u,int par){
	vis[u]=1;
	//cout<<L<<" "<<R<<" "<<p[u]<<endl;
	for(int i=0;i<(int)edge[u].size();i++){
		int v=edge[u][i].fi;
		int c=edge[u][i].se;
		if(v==par) continue;
		if(vis[v]){
			long long sum=val[u]+val[v];
			if(p[u]!=p[v]){
				if(sum!=c) out();
				else{
					if(val[u]<=0 && p[u]==0) out();
					if(val[v]<=0 && p[v]==0) out();
					if(p[u]==0){
						R=min(R,val[u]);
						L=max(L,1-val[v]+1);
					}
					else{
						R=min(R,val[v]);
						L=max(L,1-val[u]+1);
					}
				}
			}
			else{
				int sum=val[u]+val[v];
				if(abs(sum-c)%2==1) out();
				if(p[u]==0){
					if(sum<c) out();
					R=min(R,(sum-c)/2+1);
					L=max(L,(sum-c)/2+1);
				}
				else{
					if(sum>c) out();
					R=min(R,(c-sum)/2+1);
					L=max(L,(c-sum)/2+1);
				}
			}
			continue;
		}
		else{
			val[v]=c-val[u];
			p[v]=p[u]^1;
			if((p[v]==0 && val[v]<1) || (p[v]==1 && val[v]>c)) out();
			if(p[u]==0){
				R=min(R,val[u]);
				L=max(L,1-val[v]+1);
			}
			else{
				R=min(R,val[v]);
				L=max(L,1-val[u]+1);
			}
			dfs(v,u);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u>>v>>c;
		edge[u].pb(mp(v,c));
		edge[v].pb(mp(u,c));
	}
	val[1]=1;
	p[1]=1;
	dfs(1,1);
	cout<<max(0,R-L+1);
}


Measured memory_bytes: 14720
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int l = 0;
    bool ok = false;
    for(int i = 0; i < n; i++) {
        if(l < 0) break;
        if(i == n-1) ok = true;
        l = max(l,d[i]);
        l -= 10;
    }
    if(!ok) {
        cout << "no" << endl;
        return 0;
    }
    l = 0;
    ok = false;
    for(int i = n-1; i >= 0; i--) {
        if(l < 0) break;
        if(i == 0) ok = true;
        l = max(l,d[i]);
        l -= 10;
    }
    if(!ok) {
        cout << "no" << endl;
        return 0;
    }

    cout << "yes" << endl;

}

Measured memory_bytes: 4376
package main

import "fmt"

type card struct {
	suite byte
	num   int
}

func bsort(c []card) {
	for i := 0; i < len(c); i++ {
		for j := len(c) - 1; j > i; j-- {
			if c[j-1].num > c[j].num {
				c[j-1], c[j] = c[j], c[j-1]
			}
		}
	}
}

func ssort(c []card) {
	for i := 0; i < len(c); i++ {
		minv := c[i].num
		mini := i
		for j := i + 1; j < len(c); j++ {
			if minv > c[j].num {
				minv = c[j].num
				mini = j
			}
		}
		c[i], c[mini] = c[mini], c[i]
	}
}

func printcards(c []card) {
	for i := 0; i < len(c); i++ {
		fmt.Printf("%c%d", c[i].suite, c[i].num)
		if i != len(c)-1 {
			fmt.Printf(" ")
		}
	}
	fmt.Println()
}

func main() {
	var n int
	fmt.Scan(&n)
	cards := make([]card, n)
	cardsb := make([]card, n)
	cardss := make([]card, n)
	for i := range cards {
		var s string
		fmt.Scan(&s)
		cards[i].suite = s[0]
		cards[i].num = int(s[1] - '0')
	}
	copy(cardsb, cards)
	copy(cardss, cards)
	bsort(cardsb)
	printcards(cardsb)
	fmt.Println("Stable")
	ssort(cardss)
	printcards(cardss)
	for i := 0; i < n; i++ {
		if cardss[i].suite != cardsb[i].suite {
			fmt.Println("Not stable")
			return
		}
	}
	fmt.Println("Stable")
}



Measured memory_bytes: 1144
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

right = 0
for i in range(X, N+1):
    if i in A:
        right += 1

left = 0
for i in range(0, X)[::-1]:
    if i in A:
        left += 1

print(min(left, right))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

int main(void)
{
	vector<int> a;
	int fin[100010] = {};
	int i, n;
	int temp;
	int mx = 0;
	int maxsuuti;
	
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
	}
	sort(a.begin(), a.end());
	maxsuuti = a[n - 1];

	for (i = 0; i < n; i++) {
		fin[a[i]]++;
	}
	temp = 0;
	if (maxsuuti == 0) {
		cout << n << endl;
		return (0);
	}
	for (i = 1; i <= maxsuuti; i++) {
		temp = fin[i - 1] + fin[i] + fin[i + 1];
		mx = max(mx, temp);
	}
	cout << mx << endl;

	return (0);
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <list>
#include <set>
using namespace std;
 
vector<list<int>> graph;
set<int> willvisit;
int numpath = 0;
void go(int n)
{
	int t;
	set<int>::iterator it;
	it = willvisit.find(n);
	t = *it;
	willvisit.erase(it);
	if (willvisit.size() == 0)
	{
		numpath++;
		willvisit.insert(t);
		return;
	}
	for (int x : graph[n])
	{
		if ((it=willvisit.find(x)) != willvisit.end())
		{
		
			go(x);
			
		}
	}
	willvisit.insert(t);
}
int main()
{
	int N, M;
	cin >> N >> M;
	graph.resize(N+1);
	for (int i = 1; i <= N; i++)
		willvisit.insert(i);
	for (int i = 1; i <= M; i++)
	{
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	go(1);
	cout << numpath << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


q = deque()
for c in input():
    q.append(c)

rev = False
for _ in range(I()):
    query = input()
    if query.startswith('1'):
        rev = not rev
        continue
    _, f, c = query.split()
    right = f == '2'
    right = not right if rev else right
    if right:
        q.append(c)
    else:
        q.appendleft(c)

if rev:
    print(''.join(reversed(q)))
else:
    print(''.join(q))


Measured memory_bytes: 77016
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
	int K; cin >> K;
	ll* A = new ll[K];
	for (int i = K - 1; i >= 0; i--) {
		cin >> A[i];
	}

	if (A[0] != 2) {
		cout << "-1" << endl;
		return 0;
	}

	ll m = 2, M = 2;

	for (int i = 0; i < K; i++) {
		m = ((m + A[i] - 1) / A[i]) * A[i];
		M = (M - M % A[i]) + A[i] - 1;
		if (M < m) { cout << "-1" << endl; return 0; }
	}

	cout << m << " " << M << endl;

	return 0;
}

Measured memory_bytes: 1024
def push(x, stack)
  if x == "+"
    result = stack[-1] + stack[-2]
    stack.slice!(-2..-1)
    stack.push(result)
  elsif x == "-"
      result = stack[-2] - stack[-1]
      stack.slice!(-2..-1)
      stack.push(result)
    elsif x == "*"
      result = stack[-1] * stack[-2]
      stack.slice!(-2..-1)
      stack.push(result)
    else
      x = x.to_i
      stack.push(x)
    end
    return stack
  end

stack  = []
input_values = gets.chomp.split
length = input_values.length
for i in 0..(length-1)
  push(input_values[i], stack)
end

puts stack

Measured memory_bytes: 8644
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<numeric>
#include<deque>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	vector<int> x(n);
	for(int i=0;i<n;i++)
		cin>>x[i];
	int mi=1e9+7;
	for(int p=1;p<=100;p++)
	{
		int s=0;
		for(int i=0;i<n;i++)
		{
			s+=(x[i]-p)*(x[i]-p);
		}
		mi=min(mi,s);
	}
	cout<<mi<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {
    int n;
    cin >> n;
    vii jobs;
    jobs.reserve(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        jobs.push_back({b, a});
    }
    sort(jobs.begin(), jobs.end());
    int time = 0;
    bool possible = true;
    for (const auto& pair : jobs) {
        time += pair.second;
        if (time > pair.first) {
            cout << "No\n"; 
            possible = false;
            break;
        }
    }
    if (possible)
        cout << "Yes\n";
}

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


vector<vector<P>> g(51);
vector<ll> es;
bool dfs(ll v, ll tv, ll p=-1){
  if (v==tv)return true;
  for(P e:g[v]){
    ll to=e.first;
    if(to==p) continue;
    ll id=e.second;
    if (dfs(to,tv,v)){
      es.push_back(id);
      return true;
    }
  }
  return false;
}
int main() {
  ll n, m;
  cin >> n;
  rep(i,n-1) {
    ll a, b;
    cin >> a >> b;
    --a; --b;
    g[a].emplace_back(make_pair(b, i));
    g[b].emplace_back(make_pair(a, i));
  }
  cin>>m;
  vector<ll> ebit(m);
  rep(i,m){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    es=vector<ll>();
    dfs(a1,b1);
    for(auto enow:es){
      ebit[i]|=(1ll<<enow);
    }
  }
//  cout<<ebit[0]<<'k'<<endl;
  ll ans=0;
  for(ll i=0;i<(1ll<<m);i++){

    ll cnt=0;
    rep(j,m){
      if ((i>>j)&1){
        cnt|=ebit[j];
      //  cout<<cnt<<'c'<<j<<'j'<<ebit[j]<<endl;
      }
    }
    ll white = __builtin_popcountll(cnt);
    //cout<<white<<endl;
    ll now=(1ll<<(n-1-white));
     if (__builtin_popcount(i)%2==0){
       ans+=(1ll<<(n-1-white));
     }
     if (__builtin_popcount(i)%2==1){
       ans-=(1ll<<(n-1-white));
     }
  //   cout<<i<<'i'<<now<<endl;
  }
cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long long A[1<<17],L[1<<17],R[1<<17];
int g(int a, int b) {
    return b?g(b,a%b):a;
}
int main() {
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) L[i+1]=g(L[i  ],A[i]);
    for(int i=N; i--; )    R[i  ]=g(R[i+1],A[i]);
    int ans=0;
    for(int i=0; i<N; i++) ans=max(ans,g(L[i],R[i+1]));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560