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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const int N = 3e3+2;
const ll MOD = 998244353;
int n, s;
int ar[N];
ll inv[N];
ll DP[N][N]; // DP[i][j][k] -> byk subset yang jumlah ny j sampe indeks ke-i dan udah ngambil k

/*
5 8
1 2 7 6 5

{1,2,5} 3
{2,6}   2
{1,7}   2
*/

ll exp(int a, int b)
{
    if (b == 0)
        return 1;
    ll tmp = exp(a,b/2);
    tmp *= tmp;
    tmp %= MOD;
    if (b&1)
        return (tmp*a) % MOD;
    return tmp;
}

/*
(i*inv[i])%MOD == 1
a=MOD/i
b=MOD%i
MOD=a*i+b
MOD-b = a*i
MOD = 0
a*i+b = 0
a*i = -b
i = -b/a
1/i = -a/b
1/i = MOD-a/b
inv[i] = MOD - MOD/i * inv[MOD%i]
*/

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> s;
    for (int i = 1; i <= n; i++)
    {
        cin >> ar[i];
    }
    inv[1] = 1;
    for (int i = 2; i < N; i++)
    {
        inv[i] = MOD - MOD/i*inv[MOD%i]%MOD;
    }
    DP[0][0] = exp(2,n);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= s; j++)
        {
            DP[i][j] += DP[i-1][j];
            if (j >= ar[i])
                DP[i][j] += DP[i-1][j-ar[i]] * inv[2];
            DP[i][j] %= MOD;
        }
    }
    cout << DP[n][s] << '\n';
    return 0;
}

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

struct state{
    int node,del,dist;
    bool operator<(const state& r)const{
        return dist>r.dist;
    }
};

struct edge{
    int to,dist;
};

int main(){
    int N,M,C;
    while(cin >> N >> M >> C && N){
        vector<vector<edge>> g(N);
        for(int i=0;i<M;i++){
            int a,b,c;
            cin >> a >> b >> c;
            a--; b--;
            g[a].push_back({b,c});
        }
        int inf = 2e9;
        vector<vector<int>> dp(N,vector<int>(M+1,inf));
        dp[0][0] = 0;
        priority_queue<state> Q;
        Q.push({0,0,0});
        while(!Q.empty()){
            state now = Q.top(); Q.pop();
            if(dp[now.node][now.del]<now.dist) continue;
            for(auto& x:g[now.node]){
                state ne = now;
                ne.node = x.to;
                ne.dist += x.dist;
                if(dp[ne.node][ne.del]>ne.dist){
                   dp[ne.node][ne.del] = ne.dist;
                   Q.push(ne);
                }
                ne.dist = now.dist;
                ne.del++;
                if(ne.del>M) continue;
                if(dp[ne.node][ne.del]>ne.dist){
                   dp[ne.node][ne.del] = ne.dist;
                   Q.push(ne);
                }
            }
        }
        for(int i=0;i<=M;i++){
            if(dp[N-1][i]<=C){
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 5832
import math
 
A,B,H,M = map(int,input().split())
 
radH = 2*math.pi*H/12 + 30/180*math.pi*M/60
radM = 2*math.pi*M/60
 
L = math.sqrt(A**2+B**2-2*A*B*math.cos(radH-radM))
 
print(L)

Measured memory_bytes: 9416
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int x = max({a,b,c});
  int n = a+b+c-x;
  if(n==x)
  cout << "Yes" <<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}

#define ll long long
#define f first
#define s second
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	ll X;
	cin >> X;

	ll pos = 0;
	REP(i, X) {
		pos += i + 1;
		if (pos >= X) {
			cout << i + 1 << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(void){
	int n,k;
	std::string s;
    cin >> n >> k >> s; 
	if(s.substr(k-1,1)=="A"){
		s.replace(k-1, 1, "a");
		cout << s << endl;
	}else if(s.substr(k-1,1)=="B"){
		s.replace(k-1, 1, "b");
		cout << s << endl;

	}else if(s.substr(k-1,1)=="C"){
		s.replace(k-1, 1, "c");
		cout << s << endl;

	}
	return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
const int MAXN = 10 ; 
int bulb[MAXN][MAXN] ; 
int main(){
	for(int i=0;i<MAXN;i++){
		for(int j=0;j<MAXN;j++){
			bulb[i][j] = 0 ; 
		}
	}
	int n , m ; 
	cin >> n >> m ; 
	for(int i=0;i<m;i++){
		int k ;
		cin >> k ; 
		for(int j=0;j<k;j++){
			int x ; 
			cin >> x ; 
			x--;
			bulb[i][x] = 1 ; 
		}
	}
	int p[MAXN] ; 
	for(int i=0;i<m;i++){
		cin >> p[i] ; 
	}
	int res = 0 ; 
	for(int mask = 0 ; mask < (1<<n) ; mask++ ){
		vector<int> state ; 
		for(int j=0;j<n;j++){
			if ( mask & (1 << j) ){
				state.push_back(j) ; 
			}
		}
		debug() << imie(state) ; 
		int ans = 0 ; 
		for(int i=0;i<m;i++){
			int cnt = 0 ; 
			for(int c : state){
				if ( bulb[i][c] ){
					cnt++ ; 
				}
			}
			if ( cnt % 2 == p[i] ) ans++ ; 
		}
		if ( ans == m ) res++ ; 
	}
	cout << res << endl;
	return 0 ;
}


Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

const int INF=1e18;

void solve() {
    cini(n);
    cinai(a,n);
    sort(a.begin(), a.end());

    int ans=1;
    for(int i=0; i<n; i++) {
        double d=(1.0*ans)*a[i];
        if(d>INF || ans*a[i]>INF) {
            cout<<-1<<endl;
            return;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
    
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

using namespace std;

int frogCost(int h[],int d[],int n){
  if(n == 0)
    return d[0];
  else if(n == 1)
    return d[1];
  else if(d[n] != INT_MAX)
    return d[n];
    int diff1 = abs(h[n-1] - h[n]);
    int diff2 = abs(h[n-2] - h[n]);
    d[n] = min(diff1 + frogCost(h,d,n-1),diff2 + frogCost(h,d,n-2));
    return d[n];
}
int main(){
  int N;

  cin>>N;
  int heights[N];
  int cost[N];
  for(int i=0;i<N;i++){
    int h;
    cin>>h;
    heights[i] = h;
    cost[i] = INT_MAX;
  }
cost[0] = 0;
cost[1] = abs(heights[0]-heights[1]);
  // for(int j=2;j<N;j++){
  //   int diff1 = abs(heights[j-1] - heights[j]);
  //   int diff2 = abs(heights[j-2] - heights[j]);
  //     cost[j] = min(cost[j-1] + diff1,cost[j-2] + diff2);
  // }
  cout<<frogCost(heights,cost,N-1);
  return 0;
}


Measured memory_bytes: 7444
#include<iostream>
  #include<vector>
  #include<string>

  using namespace std;


  int main(){
    string W;
    string temp;
    vector<string> data;
    cin >> W;
    while(1){
      cin >> temp;
      if(temp == "END_OF_TEXT") break;
      for(string::size_type i = 0; i < temp.length(); i++){
        int num = temp[i];
        if(65<=num && num <= 90){
          num += 32;
          temp[i] = num;
        }
      }
      data.push_back(temp);
    }
    int counter = 0;
    // 検索
    for (vector<string>::size_type i = 0; i < data.size(); i++)
    {
      if(W == data[i]) counter++;
    }

    cout << counter << endl;
    
    return 0;
  }


Measured memory_bytes: 3220
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    k, t = reads()
    a = [list(x) for x in list(enumerate(reads()))]
    n = -1
    c = 0
    while sum([x[1] for x in a]):
        a = sorted(a, key=lambda x:x[1], reverse=True)
        if a[0][0] != n:
            n = a[0][0]
            a[0][1] -= 1
        else:
            if len(a) == 1:
                c += 1
                a[0][1] -= 1
            elif 0 < a[1][1]:
                a[1][1] -= 1
                n = a[1][0]
            else:
                a[0][1] -= 1
                c += 1
    print(c)

main()


Measured memory_bytes: 3064
#include<vector>
#include<algorithm>
using namespace std;
int P[300000];
int main(){
	for(int i=2;i*i<=300000;i++)if(!P[i])for(int j=i+i;j<300000;j+=i)P[j]=1;
	P[0]=P[1]=1;
	int n,p;
	while(cin>>n>>p,~p){
		vector<int> m; m.reserve(p*p);
		for(int i=n+1,c=0;c<p;i++){
			if(P[i])continue; c++;
			for(int j=i,C=0;C<p;j++)if(!P[j])m.push_back(i+j),C++;
		}
		sort(m.begin(),m.end());
		cout<<m[p-1]<<endl;
	}
	return 0;
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  int ans = 0;

  rep(i, n) {
    int a; cin >> a;
    if (a % 2 && i % 2 == 0) ++ans;
  }

  cout << ans << endl;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

typedef tuple<ll,ll,ll> T;


ll i,j,k;


int main(){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;

    ll takahashiturn=C/B;
    if(C%B)takahashiturn++;
    ll aokiturn=A/D;
    if(A%D)aokiturn++;
    if(takahashiturn<=aokiturn)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}


Measured memory_bytes: 3672
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main(){
	int n, eq=0;
	scanf("%d", &n);
	eq= 1000- (n%1000);
	if(n%1000==0)
		eq=0;
	printf("%d\n", eq);

	return 0;
}

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

#define M 1000000007LL
#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 sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"
#define llevel 20
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);
}
#define NCR 
ll inv[300000+5],fac_inv[300000+5],fac[300000+5];
void initialize()
{
	ll i;
	inv[1]=1;
	for(i=2;i<=300000;i++)
		inv[i]=(M-M/i)*inv[M%i]%M; 
	fac[0]=fac[1]=1;
	for(i=2;i<=300000;i++)
		fac[i]=i*fac[i-1]%M;
	fac_inv[0]=fac_inv[1]=1;
	for(i=2;i<=300000;i++)
		fac_inv[i]=inv[i]*fac_inv[i-1]%M;
}
ll ncr(ll n,ll r)
{
	if(n<r) return 0;
	return (fac[n]*fac_inv[r]%M)*fac_inv[n-r]%M;
}

const int N=200002;
vector<ll> v[N];
bitset<N> vis;
ll ans[N];
ll sub[N];
void dfs(ll s=1)
{
	vis[s]=1;
	ans[s]=1;
	sub[s]=1;
	for(auto j:v[s])
	{
		if(!vis[j])
		{
			dfs(j);
			sub[s]+=sub[j];
			ans[s]=(ans[s]*ans[j])%M;
			ans[s]=(ans[s]*fac_inv[sub[j]])%M;
		}
	}
	ans[s]=(ans[s]*fac[sub[s]-1])%M;
	return ;
}
void dfs2(ll s,ll n)
{
	vis[s]=1;
	for(auto j:v[s])
	{
		if(!vis[j])
		{
			ans[j]=ncr(n-1,sub[j]-1)%M*ans[s]%M*fac[sub[j]]%M*fac_inv[n-1]%M*fac[n-1-sub[j]]%M;
			dfs2(j,n);
		}
	}
}
int _runtimeTerror_()
{
	ll n,i;
	cin>>n;
	for(i=0;i<n-1;++i)
	{
		ll x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs();
	vis.reset();
	dfs2(1LL,n);
	for(i=1;i<=n;++i)
		cout<<ans[i]<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}


Measured memory_bytes: 24944
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None

ans = []


def f_positive(N, A):
    global ans

    for i in range(len(A) - 1):
        ans.append((i, i + 1))


def f_negative(N, A):
    global ans

    for i in range(len(A) - 1, 0, -1):
        ans.append((i, i - 1))


def main():
    global ans

    N = int(input())
    A = li_input()

    if min(A) >= 0:
        f_positive(N, A)
    else:
        # 全てを正の整数にする
        if abs(max(A)) >= abs(min(A)):
            maxi = A.index(max(A))
            maxv = max(A)

            for i in range(len(A)):
                A[i] += maxv
                ans.append((maxi, i))

            f_positive(N, A)
        else:
            mini = A.index(min(A))
            minv = min(A)

            for i in range(len(A)):
                A[i] += minv
                ans.append((mini, i))

            f_negative(N, A)

    print(len(ans))
    for a in ans:
        print(a[0] + 1, a[1] + 1)


main()


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;

    string S;
    cin >> S;

    int cnt_R = 0;
    int cnt_B = 0;
    
    for (int i = 0; i < N; i++){
        if (S[i] == 'R'){
            cnt_R++;
        }
        else {
            cnt_B++;
        }
    }
    
    if (cnt_R > cnt_B){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl; 
    }
}

Measured memory_bytes: 256
N,M = map(int, input().split())
S = [map(int, input().split()) for n in range(N)]
P = [list(map(int, input().split())) for n in range(M)]

for s in S:
    a,b = s
    l = 10**8*2
    ans = 0
    for i,p in enumerate(P):
        c,d = p
        if abs(a-c) + abs(b-d) < l:
            l = abs(a-c) + abs(b-d)
            ans = i
    print(ans+1)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

void push(double S[],int *top,double x){

 S[(*top)]=x;
 (*top)++;

return;
}

double pop(double S[],int *top){

 (*top)--;
 return S[(*top)];

}

int main(){
 char str[81];
 int i,j;
 int R,top;
 char temp[10];
 double S[80];
 double x1,x2;

 while(fgets(str,sizeof str,stdin)!=NULL){

   R=strlen(str);
   j=0; i=0; top=0;

   while(i<=R){

     if(i<R && str[i]!=' ')temp[j++]=str[i++];
     else {
       i++;
       temp[j]='\0';

       if(isdigit(temp[0]))
          push(S,&top,atof(temp));
       else if( !isdigit(temp[0]) && isdigit(temp[1]) )
          push(S,&top,atof(temp));/*負の数*/
       else {
          x1=pop(S,&top);
          x2=pop(S,&top);
          switch(temp[0]){
            case '+':push(S,&top,x2+x1);
                     break;
            case '-':push(S,&top,x2-x1);
                     break;
            case '*':push(S,&top,x2*x1);
                     break;
            case '/':push(S,&top,x2/x1);
                     break;
          }

       }

       j=0;

     }


   }
   printf("%.6lf\n",S[0]);

 }


return 0;
}


Measured memory_bytes: 2044
let () =
  let rec makelst k x d =
    if k * x + 1 > d then [] else k * x + 1 :: makelst (k+1) x d in
  Scanf.scanf "%d\n%d %d\n" @@ fun n d x ->
  let arr = Array.init n @@ fun _ -> 
  	Scanf.scanf "%d\n" @@ fun a -> List.length (makelst 0 a d) in
  let num = Array.fold_left (+) 0 arr in
  Printf.printf "%d\n" (x+num)

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

int main() {
	int n,k;
	scanf("%d%d", &n, &k);
	int arr[n];
	for (int i=0; i<n; i++) scanf("%d", &arr[i]);
	long long ans=LLONG_MAX;
	for (int i=0; i<(1<<(n+1)); i++) {
		int num=0;
		long long tot=0;
		int prev=0;
		for (int j=0; j<n; j++) {
			if (1<<j & i) {
				num++;
				tot+=max(prev+1-arr[j],0);
				prev=max(prev+1,arr[j]);
			}
			prev=max(prev,arr[j]);
		}
		if (num==k) ans=min(ans,tot);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<stdio.h>


int main(){
  int x,i,A[100000],p,n,r,key,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  r=n-1;
  p=0;
  
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i++;
      key=A[i];
      A[i]=A[j];
      A[j]=key;
    }
  }
  key=A[i+1];
  A[i+1]=A[r];
  A[r]=key;


  for(j=0;j<=i;j++){
    printf("%d ",A[j]);
  }
  printf("[%d] ",A[i+1]);
  for(j++;j<n-1;j++){
    printf("%d ",A[j]);
  }
  printf("%d\n",A[n-1]);
  return 0;
}

    

      



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

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

    std::vector<std::pair<int, int>> vp(N);
    for (auto& p : vp) std::cin >> p.first >> p.second;

    std::sort(vp.begin(), vp.end(), [](auto a, auto b) {
        return a.second < b.second;
    });

    int t = 0, ans = 0;
    for (auto p : vp) {
        if (p.first > t) {
            ++ans;
            t = p.second;
        }
    }

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



Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    String S;
    String T;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.S = sc.next();
        this.T = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = "";
        for (int i=0; i<N; i++) {
        	answer += String.valueOf(S.charAt(i));
        	answer += String.valueOf(T.charAt(i));
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 39448
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define per(i,n) for(int i=n;i>0;i--)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;i--);
#define push_back PB;
#define pop_back PPB;
using namespace std;
static const LL INF = 1LL<<61LL;
static const double EPS = 1e-8;
static const int mod = 100000;
typedef pair<int,int> PII;

LL dp[51][3001];

int main(){
    while(1){
        LL N,M,S;
        cin>>N>>M>>S;
        if(N==0&&M==0&&S==0)break;
        N*=N;
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        FOR(i,1,M){
            per(j,N){
                FOR(k,i,S){
                    dp[j][k]+=dp[j-1][k-i]%mod;
                }
            }
        }
        cout<<dp[N][S]%mod<<endl;
    }
    return 0;
}

Measured memory_bytes: 2360
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
#define FOR(i,x,y) for(int i=(int)x; i<(int)y; ++i)
#define REP(i,y) FOR(i, 0, y)
constexpr int INF = 1<<30;
int N;
vector<vint> X(18, vint(2));
vint V_(18);
vint V;
vint Vb(18);
int search(int F){
  int tmp = 0;
  REP(i,N){
    V[i] = X[i][F%2];
    V_[i] = V[i];
    tmp += F%2;
    Vb[i] = F%2;
    F>>=1;
  }
  sort(V.begin(), V.end());
  int ans = 0;
  REP(i,N){
    bool flag = false;
    FOR(j,i,N){
      if(V[i]==V_[j] && (abs(i-j))%2==Vb[j]){
        flag = true;
        ans += abs(i-j);
        for(int k=j-1; k>=i; --k){
          V_[k+1] = V_[k];
          Vb[k+1] = (Vb[k]+1)%2;
        }
        break;
      }
    }
    if(!flag || tmp%2==1) return INF;
  }
  return ans;
}
int main(){
  cin >> N;
  V.resize(N);
  REP(i,N) cin >> X[i][0];
  REP(i,N) cin >> X[i][1];
  int ans=INF;
  REP(i,1<<N) ans = min(ans, search(i));
  if(ans==INF) ans=-1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main()
{
	int a; cin >> a;
	int t[3];

	for(int i=0; i<a; i++){
		cin >> t[0] >> t[1] >> t[2];
		sort(t,t+3);
		if( (t[0]*t[0]+t[1]*t[1]) == (t[2]*t[2])){cout << "YES" << endl;}
		else{cout << "NO" << endl;}
	}

	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


void solve(){
	int n; cin>>n;
  vector<ll> H;
  rep(i,n){
    ll h; cin>>h;
    H.PB(h);
  }
  bool ans = true;
  ll m = H[n-1];
  REP(i,n){
    if(H[i]-1>m) ans=false;
    m=min(m,H[i]);
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll ans = 0;
    ll N = S.size();
    ll cnt = 0;
    rep(i,0,N){
        if(S[i] == 'S'){
            cnt++;
        }else{
            if(cnt > 0){
                cnt--;
                ans += 2;
            }
        }
    }
    print(N - ans);

}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3000;
double dp[MAX_N + 1][MAX_N + 1];
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    // (i, n) => prob
    // 0-originでi番より前のコインを投げてn個の表が出る確率prob
    for(int n = 0; n <= N; n++) {
        dp[0][n] = (n == 0);
    }
    for(int i = 0; i <= N; i++) {
        double p;
        cin >> p;
        for(int n = 0; n <= N; n++) {
            dp[i + 1][n] = dp[i][n] * (1 - p);
            if(n > 0) dp[i + 1][n] += dp[i][n - 1] * p;
        }
    }
    double ans = 0;
    for(int n = N / 2 + 1; n <= N; n++) {
        ans += dp[N][n];
    }
    cout << std::fixed << std::setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 70656
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <queue>
#include <limits.h>
using namespace std;

typedef long long ll;

const int N = 3000;
int n;
double p[N], dp[N][N];

double calc(int at, int head) {
	if (at == n)
		return head * 2 > n ? 1 : 0;
	double &res = dp[at][head];
	if (res == res)
		return res;
	res = calc(at + 1, head + 1) * p[at] + calc(at + 1, head) * (1 - p[at]);
	return res;
}

int main(int argc, char **argv) {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lf", &p[i]);
	memset(dp, -1, sizeof(dp));
	printf("%.11lf\n", calc(0, 0));
	return 0;
}


Measured memory_bytes: 70784
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
// #define modd 2019

#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>

#include <cassert>
// #include <algorithm>
#include <functional>
using namespace std;

int euk(int a, int b){
    if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最大公約数を出力 */
//   printf("最大公約数 = %d\n", b);
 
  return b;

}

int main(){
  int a, b;
  cin >> a >> b;
  int aa = a+b;
  int bb = a-b;
  int cc = a*b;
  cout << max(aa,max(bb, cc));

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int charidx(char c) {
	return c - 'a';
}

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

	string s; cin >> s;
	string t; cin >> t;

	vector<vector<int>> count(26);
	FOR_LT(i, 0, s.size()) {
		count[charidx(s[i])].push_back(i);
	}

	int64_t p = 0;
	int64_t val = 0;
	FOR_LT(i, 0, t.size())
	{
		int ci = charidx(t[i]);
		vector<int>& poss = count[ci];
		if (poss.empty()) {
			cout << -1 << endl;
			return 0;
		}

		auto it = lower_bound(poss.begin(), poss.end(), p);
		if (it == poss.end()) {
			val++;
			it = poss.begin();
		}
		p = *it + 1;
	}

	cout << (val * s.size()) + p << endl;

	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    int n,d;
    cin>>n>>d;
    int ans=0;
    rep(i,n)
    {
        double x,y;
        cin>>x>>y;
        double temp=x*x+y*y;
        temp+=0.0;
        temp=sqrt(temp);
        if(temp<=(double)d) ans++;
    }
    cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 11020
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input, marker::*};
//use std::collections::HashSet;
use std::collections::*;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;
//use petgraph::unionfind::UnionFind;

#[fastout()]
fn main() {
    input! {
        N:usize, mut S:[String;N]
    }
    //S.sort();
    //println!("{:?}", S);
    let emptystring = "".to_string();
    let mut m = HashMap::new();
    let mut set = BTreeSet::new();
    //let S: Vec<String> = S.iter().map(|s| s.iter().collect::<String>()).collect();
    let mut max = 0;
    for i in 0..N {
        *m.entry(S[i].clone()).or_insert(0) += 1;
        let k = *m.get(&S[i]).unwrap();
        max = std::cmp::max(max, k);
        set.insert(&S[i]);
    }
    for s in set {
        //        let s = S[i];
        if *m.get(s).unwrap() == max {
            println!("{}", s.to_string());
        }
    }
}


Measured memory_bytes: 33628
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define MAXN 200010
#define INF 0x3f3f3f3f
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c;
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;
}
int Bdj[MAXN],Vb[MAXN*2],nxtb[MAXN*2],cb;
void Add(int u,int v)
{
	cb++;Vb[cb]=v,nxtb[cb]=Bdj[u];Bdj[u]=cb;
}
int n,rt,s,ans;
int dep[MAXN],fa[MAXN],e[MAXN][2],lon[MAXN],vis[MAXN];
void dfs(int u)
{
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=fa[u])
		{
			dep[V[i]]=dep[u]+1;
			fa[V[i]]=u;
			dfs(V[i]);
		}
}
int dis[MAXN];
queue<int>Q;
void bfs()
{
	dis[s]=0;
	vis[s]=1;
	Q.push(s);
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		for(int i=Bdj[u];i;i=nxtb[i])
			if(!vis[Vb[i]])
			{
				dis[Vb[i]]=dis[u]+1;
				if(dis[Vb[i]]<dep[Vb[i]])
				{
					vis[Vb[i]]=1;
					Q.push(Vb[i]);
				}
			}
	}
}
int check(int u,int v)
{
	if(dep[u]<dep[v]) swap(u,v);
	int k=dep[u]-dep[v];
	if(k==0) return fa[u]!=fa[v];
	if(k==1) return fa[u]!=v;
	if(k==2) return fa[fa[u]]!=v;
	return 1;
}
void Clear()
{
	for(int i=1;i<=n;i++)
		Adj[i]=Bdj[i]=vis[i]=lon[i]=0;
	c=cb=0;
	ans=0;
}
void Read(int &x)
{
	x=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
}
int main()
{
//	freopen("coalesce.in","r",stdin);
//	freopen("coalesce.out","w",stdout);
	scanf("%d%d%d",&n,&s,&rt);
	int u,v,flag=0;
	for(int i=1;i<n;i++)
	{
		Read(e[i][0]);
		Read(e[i][1]);
	}
	for(int i=1;i<n;i++)
	{
		Read(u);Read(v);
		AddEdge(u,v);
		AddEdge(v,u);
	}
	dfs(rt);
	for(int i=1;i<n;i++)
		if(check(e[i][0],e[i][1]))
			lon[e[i][0]]=lon[e[i][1]]=1;
		else Add(e[i][0],e[i][1]),Add(e[i][1],e[i][0]);
	bfs();
	for(int i=1;i<=n;i++)
		if(vis[i]&&lon[i])
		{
			flag=1;
			break;
		}
		else if(vis[i])
			ans=max(ans,dep[i]);
	if(flag) printf("-1\n");
	else printf("%d\n",ans*2);
}

Measured memory_bytes: 19200
n,m = map(int,input().split())
a = []
b = []
raw = []
ans = 0
for i in range(n):
  raw.append(list(map(int,input().split())))
raw.sort(key=lambda x:x[0])
for i in range(n):
  ans = ans + raw[i][0] * min(raw[i][1],m)
  m = m - min(raw[i][1],m)
  if m == 0:
    break
print(ans)

      


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pi;
typedef vector<int> &via;
typedef vector<int> vi;
typedef vector<pi> vii;
typedef vector<ll> &vla;
typedef vector<ll> vl;

int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d)
    {
        cout << "Yes";
    }
    else if (abs(a - b) <= d && abs(b - c) <= d)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int[] a = new int[10];
		String str;;
		
		while(scan.hasNext()){
			str = scan.next();
			char[] ch = str.toCharArray();

			for(int i = 0; i < 10; i++){
				a[i] = Integer.parseInt("" + ch[i]);

			}
			
			for(int i = 0; i < 9; i++){
				for(int j = 0; j < 9 - i; j++){
					a[j] = a[j] + a[j + 1];
					if(a[j] >= 10)a[j] -= 10;
				}
			}
			System.out.println(a[0]);
		}
	}
}

Measured memory_bytes: 25696
import bisect

n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))

point = 0

for i in t:
    if bisect.bisect(s,i)-bisect.bisect_left(s,i) > 0:
        point += 1
    
print(point)


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a, b;
    cin >> a >> b;
    if(a < b)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 10 << endl;
    }
    return 0;
}


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

using namespace std;

#define FOR(i,n)	for(int i=0;i<(int)n;i++)
#define FOB(i,n)	for(int i=n;i>=1;i--)
#define MP(x,y)	make_pair((x),(y))
#define ii pair<int, int>
#define lli long long int
#define ulli unsigned long long int
#define lili pair<lli, lli>
#ifdef EBUG
#define DBG	if(1)
#else
#define DBG	if(0)
#endif
#define SIZE(x) int(x.size())
const int infinity = 2000000999 / 2;
const long long int inff = 4000000000000000999;

typedef complex<long double> point;

template<class T>
T get() {
    T a;
    cin >> a;
    return a;
}

template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {
    out << "[" << par.first << ";" << par.second << "]";
    return out;
}

template <class T>
ostream& operator<<(ostream& out, const set<T> &cont){
    out << "{";
    for (const auto &x:cont) out << x << ", ";
    out << "}";
    return out;
}

template <class T, class U>
ostream& operator<<(ostream& out, const map<T,U> &cont){
    out << "{";
    for (const auto &x:cont) out << x << ", ";
    out << "}"; return out;
}

template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  FOR(i, v.size()){
    if(i) out << " ";
    out << v[i];
  }
  out << endl;
  return out;
}

bool ccw(point p, point a, point b){
  if((conj(a - p) * (b - p)).imag() <= 0) return(0);
  else return(1);
}

int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    
    int n = get<int>();
    vector<pair<int, ii> > P;
    P.push_back({0, {0, 0}});
    FOR(i, n){
        int t = get<int>();
        int x = get<int>();
        int y = get<int>();
        P.push_back({t, {x, y}});
    }
    
    sort(P.begin(), P.end());
    
    FOR(i, n){
        int lx, ly, x, y;
        lx = P[i].second.first, ly = P[i].second.second, x = P[i + 1].second.first, y = P[i + 1].second.second;
        int dt = P[i + 1].first - P[i].first;
        if(abs(lx - x) + abs(ly - y) > dt){
            cout << "No" << endl;
            return 0;
        }
        if(((abs(lx - x) + abs(ly - y)) % 2) != (dt % 2)){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
    
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 175, task a, 2020/08/15
//ms,
/*
*/

int main(void){
  string S;
  int ans=0;
  int pre_is_r;

  cin >>S;
  if(S=="RRR") ans=3;
  else if(S=="RRS" || S=="SRR") ans=2;
  else if(S=="SSS") ans=0;
  else  ans=1;

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


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <cmath>

#include <list>
#include <queue>
#include <algorithm>

#define INF 1000000000

using namespace std;

int r;
int c;
char maze[50][50];
int sx, sy;
int gx, gy;

typedef pair<int, int> P;

int n, m;
int a[200001];
int b[200001];

vector<int> connection[200001];

int start;
int goal;

int d[200001];
int guide[200001];

int bfs(void)
{
    queue<P> que;

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

    int d[50][50];
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            d[i][j] = INF;
        }
    }

    que.push(P(sx, sy));
    d[sy][sx] = 0;

    while (que.size()) {
        P p = que.front();
        que.pop();

        int current_x = p.first;
        int current_y = p.second;

        if (current_x == gx && current_y == gy) break;

        for (int i = 0; i < 4; i++) {
            int new_x = current_x + dx[i];
            int new_y = current_y + dy[i];
            if (d[new_y][new_x] == INF && maze[new_y][new_x] == '.' && 0 <= new_x && new_x < c && 0 <= new_y && new_y <= r) {
                que.push(P(new_x, new_y));
                d[new_y][new_x] = d[current_y][current_x] + 1;
            }
        }
    }
    return d[gy][gx];
}

void bfs2(void)
{
    queue<int> que;
    
    for (int i = 1; i <= n; i++) {
        d[i] = INF;
    }
    d[start] = 0;

    que.push(start);
    while (que.size()) {
        int p = que.front();
        que.pop();

        for (int i = 0; i < connection[p].size(); i++) {
            int new_p = connection[p][i];
            if (d[new_p] == INF) {
                que.push(new_p);
                d[new_p] = d[p] + 1;
                guide[new_p] = p;
            }
        }
    }

    return;
}

int main(void)
{
    // cin >> r >> c;
    // cin >> sy >> sx;
    // cin >> gy >> gx;
    // for (int i = 0; i < r; i++) {
    //     for (int j = 0; j < c; j++) {
    //         cin >> maze[i][j];
    //     }
    // }

    // sx--; sy--; gx--; gy--;

    // int ans = bfs();
    // cout << ans << endl;

    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i];
        connection[a[i]].push_back(b[i]);
        connection[b[i]].push_back(a[i]);
    }

    for (int i = 1; i <= n; i++) {
        guide[i] = -1;
    }

    start = 1;
    bfs2();
    bool flag = false;
    for (int i = 2; i <= 2; i++) {
        if (guide[i] == -1) {
            flag = true;
            break;
        }
    }
    if (!flag) {
        cout << "Yes";
        for (int i = 2; i <= n; i++) {
            cout << endl << guide[i];
        }
    } else {
        cout << "No";
    }
    
    return 0;
}


Measured memory_bytes: 14588
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3e3 + 33, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int half = 500000004;
int n, q, a[maxn], dp[maxn][maxn], eq[maxn][maxn];
vector<pair<pi, int>> upd, upd2;
void process(int x, int y) {//update dp[x][i]
	for(int i = 1; i <= n; i++) {
		if(i==y||i==x) continue;
		upd.pb({{x, i}, (dp[x][i] + dp[y][i])*1ll*half%mod});
		upd.pb({{i, x}, (dp[i][x] + dp[i][y])*1ll*half%mod});
	}
	for(int i = 1; i <= n; i++) {
		if(i==y||i==x) continue;
		upd2.pb({{x, i}, (eq[x][i] + eq[y][i])*1ll*half%mod});
		upd2.pb({{i, x}, (eq[i][x] + eq[i][y])*1ll*half%mod});
	}
}
void apply() {
	for(auto i : upd)
		dp[i.first.first][i.first.second] = i.second;
	upd.clear();
	for(auto i : upd2)
		eq[i.first.first][i.first.second] = i.second;
	upd2.clear();
}
void compress() {
	vi t;
	for(int i = 1; i <= n; i++) t.pb(a[i]);
	sort(all(t));
	for(int i = 1; i <= n; i++) a[i] = lower_bound(all(t), a[i]) - t.begin() + 1;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	compress();
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			dp[i][j] = a[i] < a[j];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			eq[i][j] = a[i] == a[j];
	
	ll pw = 1;
	for(int i = 0; i < q; i++) pw = (pw<<1)%mod;		
	
	int x, y;
	while(q--) {
		cin >> x >> y;
		process(x, y);
		process(y, x);
		apply();
		dp[x][y] = dp[y][x] = (mod+1-eq[x][y])*1ll*half%mod;
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = i+1; j <= n; j++) {
			(ans += dp[j][i])%=mod;
		}
	cout << pw*ans%mod;
}



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

using namespace std;
#define li long long int


li solve(li *a,li *b,li *c,li i,li n,li *dp,li f_a,li f_b,li f_c)
{
    //BaseCase
    if(i>n-1)
    {
        return 0;
    }
    //LOOKUP


    //Recursion
    li op1,op2,op3;
    op1=op2=op3=-1;
    if(f_a!=1)
    {
         op1=a[i]+solve(a,b,c,i+1,n,dp,1,0,0);
    }


     if(f_b!=1){
          op2=b[i]+solve(a,b,c,i+1,n,dp,0,1,0);
     }

     if(f_b!=1){
          op3=c[i]+solve(a,b,c,i+1,n,dp,0,0,1);
     }
    return max(op1,max(op2,op3));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    li n,i,j,k;
    cin>>n;
    li dp[3]={0};
    li d[3];



    for(k=0;k<n;k++)
    {
        for(i=0;i<3;i++)
            cin>>d[i];
        li new_dp[3]={0};
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                if(i!=j)
                {
                    new_dp[j]=max(new_dp[j],dp[i]+d[j]);
                }
            }



        }
        for(i=0;i<3;i++)
            dp[i]=new_dp[i];

    }


    cout<<max(dp[0],max(dp[1],dp[2]));

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll solve(ll N, ll X) {
  if(N==1) {
    if(X==1) return 0;
    if(X==2) return 1;
    if(X==3) return 2;
    if(X==4) return 3;
    if(X==5) return 3;
  }
  if(X==1) return 0;
  if(X<=1+pow(2, N+1)-3) return solve(N-1, X-1);
  if(X<=2+pow(2, N+1)-3) return 1+solve(N-1, X-2);
  if(X<=2+2*(pow(2, N+1)-3)) return 1+solve(N-1, pow(2, N+1)-3)+solve(N-1, X-2-(pow(2, N+1)-3));
  return 1+2*solve(N-1, pow(2, N+1)-3);
}

int main() {
  ll N, X;
  cin>>N>>X;
  cout<<solve(N, X)<<endl;
}



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

int main() {
  map<int, int> m;
  for (int i = 0; i < 3; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  for (auto p : m) {
    if (p.second == 1) {
      cout << p.first << endl;
    }
  }
  return 0;
}

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s; cin >> s;
	int N = int(s.size());

	auto ways = [&](int n) -> ll {
		return 1ll << max(n-1, 0);
	};

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll x = 0;
		for (int j = i+1; j <= N; j++) {
			x = 10 * x + s[j-1] - '0';
			ans += x * ways(i) * ways(N-j);
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 100005;

pls give {
    AC;
    int n, maxi=0;
    string a;
    vector<string> ans;
    cin >> n;
    map<string, int> m;
    for (int i=0; i<n; i++) {
        cin >> a;
        m[a]++;
        maxi = max(maxi, m[a]);
    }
    for (auto i : m){
        if (i.second >= maxi) ans.pb(i.first);
    }
    qsort(ans);
    for (auto i : ans) cout << i << endl;
}

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

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

    vector<int> v(n, 0);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v.at(--a)++;
        v.at(--b)++;
    }

    for (int x : v)
        cout << x << endl;
}

Measured memory_bytes: 3632
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = int64_t;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int n;
    cin>>n;
    vector<vector<int>>vec(n,vector<int>(3));
    rep(i,n){
      cin>>vec.at(i).at(0)>>vec.at(i).at(1)>>vec.at(i).at(2);
    }
    int hc=-1;
    int h;
    int x,y;
    x=-1;
    y=-1;
    rep(i,101){
        rep(j,101){
            rep(k,n){
                if(vec.at(k).at(2)!=0){
                    hc=abs(vec.at(k).at(0)-i);
                    hc+=abs(vec.at(k).at(1)-j);
                    hc+=vec.at(k).at(2);
                    //cout<<i<<j<<k<<hc<<endl;
                    rep(m,n){
                    h=abs(vec.at(m).at(0)-i);
                    h+=abs(vec.at(m).at(1)-j);
                    h=hc-h;
                    h=max(h,0);
                    if(h!=vec.at(m).at(2)){
                        hc=-1;
                        goto SKIP; }}
                x=i;
                y=j;
                cout<<x<<" "<<y<<" "<<hc<<endl;
                return 0;}
                SKIP:;
                
            }

        }
    }
    
}



Measured memory_bytes: 3604