akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,a,b,tc;
    //string s;
    LL x;
    cin>>x>>n;
    set<LL> s;
    for(i=0;i<n;i++)
    {
        cin>>j;
        s.insert(j);
    }

    for(i=0;;i++)
    {
        LL p=x+i;
        LL q=x-i;
        swap(p,q);
        if(s.find(p)==s.end())
        {
            cout<<p<<endl;
            return 0;
        }
        if(s.find(q)==s.end())
        {
            cout<<q<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3664
require 'set'
n = gets.chomp.to_i
s = gets.chomp.split(//)

a = Set.new()

left = [Set.new([s.first])]
right = Array.new(n-2)
right[-1] = Set.new([s.last])

1.upto(n-3).each do |i|
  left[i] = left[i-1].dup
  left[i].add s[i]
  # break if left.size == 10
end

(n-3).downto(1).each do |i|
  # p right
  right[i-1] = right[i].dup
  right[i-1].add s[i+1]
  # break if right.size == 10
end

if false
  p left
  p right
  p left.size
  p right.size
  exit
end

1.upto(n-2).each do |i|
  left[i-1].each do |l|
    right[i-1].each do |r|
      a.add l + s[i] + r
    end
  end

  break if a.size == 1000
  # break if i == 1000
end

puts a.size


Measured memory_bytes: 61180
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
#define INF 1e14
typedef long long int ll;
const ll N=1e6+5;
bool x[N+1]={false};
ll fast(ll n,ll a)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a)%Mod;
        if(n%2==0)
        {
            return (((res%Mod)*(res%Mod))%Mod);
        }
        else{
            return (((((res%Mod)*a)%Mod)*res)%Mod);
        }
    }
}
ll dp[2005][2005];
int main()
{
  ll n,m;
  cin>>n>>m;
  ll i,j;
  ll a[n],b[m];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(j=0;j<m;j++)
  {
      cin>>b[j];
  }
  for(i=1;i<=n;i++)
  {
      for(j=1;j<=m;j++)
      {

          if(a[i-1]==b[j-1])
            dp[i][j]+=1+dp[i-1][j-1];

              dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];

          dp[i][j]%=Mod;
          if(dp[i][j]<0)
          {
              dp[i][j]+=Mod;
          }
      }
  }
  cout<<dp[n][m]+1;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll X, Y;
    cin >> X >> Y;
    ll ans = 0;
    if (X == 1)
        ans += 300000;
    else if (X == 2)
        ans += 200000;
    else if (X == 3)
        ans += 100000;
    if (Y == 1)
        ans += 300000;
    else if (Y == 2)
        ans += 200000;
    else if (Y == 3)
        ans += 100000;

    if (X == 1 && Y == 1)
        ans += 400000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
/*
AOJ - ITP1_5_B
Date: 20180914
Author: Mikoron
 */

#include<stdio.h>

int main(void) {

        int H, W;
        int i, j;

        while(1) {
                scanf("%d %d", &H, &W);
                if(H == 0 && W == 0) break;
                for(i = 0; i < H; i++) {
                        for(j = 0; j < W; j++) {
                                if(i == 0 || i == H - 1 || j == 0 || j == W - 1) {
                                        printf("#");
                                }else {
                                        printf(".");
                                }
                        }
                        printf("\n");
                }
                printf("\n");
        }

}



Measured memory_bytes: 2120
# -*- coding: utf-8 -*-

A,B,C,X,Y = map(int, input().split())

m = []

#Cを買わない
m.append(A*X + B*Y)

#Aを買い足す
if X > Y:
    m.append( (X-Y)*A + 2*Y*C )
#Bを買い足す
if X < Y:
    m.append( (Y-X)*B + 2*X*C )
#Cだけ買う
if X < Y:
    m.append(2*Y*C)
elif X == Y:
    m.append(2*Y*C)
else:
    m.append(2*X*C)

print(min(m))

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

int main()
{
    cin >> N;
    vector<ll> a(3 * N);
    rep(i, 0, 3 * N)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = N; i < 3 * N; i += 2)
    {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5536
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b;
  string temp1="", temp2="";
  
  cin >> a >> b;
  for(int i=0;i<b;i++){
    temp1 += to_string(a);
  }
  for(int i=0; i<a; i++){
    temp2 += to_string(b);
  }
  if(temp1<=temp2){
    cout << temp1;
  }
  else{
    cout << temp2;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<complex>
using namespace std;

int main(){
    char tmp[10];
    int x,y,f,cnt=0;
    while (scanf("%s",tmp)!=EOF) {
        f=0;
        if (tmp[0]==tmp[1] && tmp[1]==tmp[2] && tmp[2]!='s') {
            printf("%c\n",tmp[0]);
            f=1;
        } else if (tmp[3]==tmp[4] && tmp[4]==tmp[5] && tmp[5]!='s') {
            printf("%c\n",tmp[3]);
            f=1;
        } else if (tmp[6]==tmp[7] && tmp[7]==tmp[8] && tmp[8]!='s') {
            printf("%c\n",tmp[6]);
            f=1;
        } else if (tmp[0]==tmp[3] && tmp[3]==tmp[6] && tmp[6]!='s') {
            printf("%c\n",tmp[6]);
            f=1;
        } else if (tmp[1]==tmp[4] && tmp[4]==tmp[7] && tmp[7]!='s') {
            printf("%c\n",tmp[7]);
            f=1;
        } else if (tmp[2]==tmp[5] && tmp[5]==tmp[8] && tmp[8]!='s') {
            printf("%c\n",tmp[8]);
            f=1;
        } else if (tmp[0]==tmp[4] && tmp[4]==tmp[8] && tmp[8]!='s') {
            printf("%c\n",tmp[8]);
            f=1;
        } else if (tmp[2]==tmp[4] && tmp[4]==tmp[6] && tmp[6]!='s') {
            printf("%c\n",tmp[6]);
            f=1;
        }
        if (f==0) printf("d\n");
    }
    return 0;
}

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

int main(){
  int a,b,ans=0;
  cin>>a>>b;
  ans+=max(a,b);
  if(a>b) ans+=max(a-1,b);
  else ans+=max(a,b-1);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;


vector<vector<int> > rotate90(const vector<vector<int> > &am)
{
	int m = am.size();
	vector<vector<int> > r = vector<vector<int> >(m, vector<int>(m));

	for (int i = 0; i < m; i++)
		for (int j = 0; j < m; j++)
			r[j][m - i - 1] = am[i][j];
	return r;
}

pair<int, int> match(const vector<vector<int> > &an, const vector < vector<int> > &am)
{
	vector<vector<int> > a[4];
	a[0] = am;
	for (int i = 0; i < 3; i++)
	{
		a[i + 1] = rotate90(a[i]);
	}
	int m = am.size();
	int n = an.size() - m + 1;
	vector<pair<int, int> > result = vector<pair<int, int> >();
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < 4; k++)
			{
				for (int p = 0; p < m; p++) //??¨?????¢?????????????????§??????
				{

					bool ok = false;
					for (int q = 0; q < m; q++)
					{
						if (a[k][p][q] != -1)
						{
							if (a[k][p][q] != an[i + p][j + q])
							{
								ok = true;
								break;
							}
							else if (p + q == 2 * (m - 1))
							{
								for (int s = 0; s < m; s++)
								{
									bool ok2 = false;
									for (int t = 0; t < m; t++)
									{
										if (a[k][s][t] != -1)
										{
											result.push_back({ i + s + 1,j + t + 1 });
											ok2 = true;
											break;
										}
									}
									if (ok2) break;
								}
							}
						}
						else if (p + q == 2 * (m - 1))
						{
							for (int s = 0; s < m; s++)
							{
								bool ok2 = false;
								for (int t = 0; t < m; t++)
								{
									if (a[k][s][t] != -1)
									{
										result.push_back({ i + s + 1,j + t + 1 });
										ok2 = true;
										break;
									}
								}
								if (ok2) break;
							}
						}
					}
					if (ok) break;
				}

			}
			if (!result.empty())
			{
				int pos = 0;
				for (int h = 1; h < result.size(); h++)
				{
					if (result[pos].first > result[h].first)
						pos = h;
					else if (result[pos].first == result[h].first && result[pos].second > result[h].second)
						pos = h;
				}
				return result[pos];
			}
		}
	}
	return { -1,-1 };
}

int main()
{
	int n, m;
	vector<vector<int> > an, am;
	while (cin >> n >> m && n != 0)
	{
		an = vector<vector<int> >(n);
		for (int i = 0; i < n; i++)
		{
			an[i] = vector<int>(n);
			for (int j = 0; j < n; j++)
				cin >> an[i][j];
		}
		am = vector<vector<int> >(m);
		for (int i = 0; i < m; i++)
		{
			am[i] = vector<int>(m);
			for (int j = 0; j < m; j++)
				cin >> am[i][j];
		}
		pair<int, int> res = match(an, am);
		if (res.first > -1)
			cout << res.second << " " << res.first << endl;
		else
			cout << "NA" << endl;
	}

	return 0;
}

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


int main()
{

  int N;
  cin >> N;

  int a;
  int B[N+1];
  for(int i=0;i<N+1;i++)
  {
    B[i] = 0;
  }
  
  
  for(int i=0;i<N-1;i++)
  {
    cin >> a;
    B[a]++;
  }

  for(int i=1;i<N+1;i++)
  {
    cout << B[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4392
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <list>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

set<int> T[SIZE];

int imain()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int a,b;
	for(int i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		T[a].insert(b);
		T[b].insert(a);
	}
	for(set<int>::iterator it=T[1].begin();it!=T[1].end();it++){
		if(T[*it].find(n)!=T[*it].end())return 1;
	}
	return 0;
}

int main(){
	if(imain()==1)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");

	return 0;
}


Measured memory_bytes: 28416
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [_p-1 for _p in p]
c = list(map(int, input().split()))

ans = -float('inf')

visited = [False] * n
ss = []
for i in range(n):
    if visited[i]: continue
    cur = i
    s = []
    while not visited[cur]:
        visited[cur] = True
        s.append(c[cur])
        cur = p[cur]
    ss.append(s)

for s in ss:
    m = len(s)
    cumsum = [0] * (m*2+1)
    for i in range(2*m):
        cumsum[i+1] = cumsum[i] + s[i%m]
    
    amari = [-float('inf')] * m
    for i in range(m):
        for j in range(m):
            amari[j] = max(amari[j], cumsum[i+j] - cumsum[i])
    
    for r in range(0, m):
        if r > k: continue
        q = (k-r)//m
        if r==0 and q==0:
            continue
        
        if cumsum[m] > 0:
            ans = max(ans, amari[r] + cumsum[m]*q)
        elif r > 0:
            ans = max(ans, amari[r])

print(ans)


Measured memory_bytes: 75312
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		scanner.close();
		
		if((str.contains("N") == str.contains("S")) && (str.contains("W") == str.contains("E"))){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    
    rep(i,n) cin >> A[i];
    sort(A.begin(), A.end());
   
    int ans = 0;
 
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            int a = A[i], b = A[j];
            int r = lower_bound(A.begin(), A.end(), a+b) - A.begin();
            int l = j+1;
            ans += max(0, r-l);
            
 
        }
    }

    
    cout << ans << endl;
    

}


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

int main() {
  int N, M;
  cin >> N >> M;
  int H[N+1];
  int G[N+1];
  for (int i=1; i<N+1; i++){
    cin >> H[i];
  }
  for (int i=1; i<N+1; i++){
    G[i]=1;
  }
  for (int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    if (H[a]>=H[b])
      G[b]=0;
    if (H[b]>=H[a])
      G[a]=0;
  }
  int ans=0;
  for (int i=1; i<N+1; i++){
    ans+=G[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4404
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    cout << fixed << setprecision(15);

    long double n, k;
    cin >> n >> k;

    long double ans = 0;
    for(int i = 1; i <= n; i++) {
        int score = i;
        int cnt = 0;
        while(score < k) {
            score *= 2.0;
            cnt++;
        }
        long double res = 1.0;
        for(int i = 0; i < cnt; i++) res *= 0.50;
        res /= n;
        ans += res;
        // ans += pow(0.50, cnt) / n;
        // cout << i << ": " << cnt << endl;
    }

    cout << ans << endl;

    return 0;
}

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

const int MAX = 1000000;
vector<int> D(MAX+1);

void pre(){
    for(int i=1;i<=MAX;i++)
        D[i] = i;

    vector<bool> is_prime(MAX+1,true);
    for(int i=2;i*i<=MAX;i++){
        if(!is_prime[i]) continue;
        else{
            for(int j=i;j<=MAX;j+=i){
                is_prime[j] = false;
                D[j] = min(D[j],i);
            }
        }
    }
}

bool judge_pairwise(int N,vector<int>& A){
    vector<bool> primes(MAX+1,false);
    for(int i=0;i<N;i++){
        int a = A[i];
        while(a > 1){
            if(primes[D[a]])
                return false;
            else{
                int t = D[a];
                primes[t] = true;
                do{ a /= t; }while(D[a] == t);
            }
        }
    }
    return true;
}

int multi_gcd(int N,vector<int>& A){
    if(N == 2)  return gcd(A[0],A[1]);
    else        return gcd(A[N-1],multi_gcd(N-1,A));
}

/*bool judge_setwise(int N,vector<int>& A){  
    int tmp = A[N-1];
    while(N > 1){
        tmp = gcd(tmp,A[N-2]);
        if(tmp == 1) return true;
        else N--;
    }
    return false;
}*/

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++)
        cin >> A[i];

    pre();
    bool is_pairwise = judge_pairwise(N,A);
    //bool is_setwise = judge_setwise(N,A);
    bool is_setwise = multi_gcd(N,A) == 1 ? true : false;

    if(is_pairwise)
        cout << "pairwise coprime";
    else if(is_setwise)
        cout << "setwise coprime";
    else
        cout << "not coprime";

    return 0;
}

Measured memory_bytes: 42408
def main():
    N = int(input())

    withdraws = []
    for i in range(N):
        if N < 9**i:
            break
        withdraws.append(9**i)
    for i in range(1, N):
        if N < 6**i:
            break
        withdraws.append(6**i)
    withdraws.sort(reverse=True)
    W = len(withdraws)

    dp = [[10**9 for i in range(N + 1)] for j in range(W + 1)]
    dp[0][0] = 0
    for i in range(1, W+1):
        for n in range(N + 1):
            if n - withdraws[i-1] >= 0:
                dp[i][n] = min(dp[i-1][n], dp[i][n - withdraws[i-1]] + 1)
            else:
                dp[i][n] = dp[i-1][n]
    print(dp[W][N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 107884
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int total_m = 0;
	
	total_m += (m2 - m1);
	if (total_m < 0) {
		total_m += 60;
		h2--;
	}
	total_m += (h2 - h1) * 60;
	cout << total_m - k << endl;
}

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

	solve();
}


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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    string N=in<string>();
    ll ans;ans=0;
    ll sum_d;sum_d=0;
    REP(j,N.size()){
        sum_d+=N[j]-'0';
    }
    if(N.size()==1){
        cout<<N[0]-'0'<<endl;
        return 0;
    }    
    if(sum_d==9*N.size()){
        cout<<9*N.size()<<endl;;
        return 0;
    }
    if(sum_d==N[0]-'0'+9*(N.size()-1)){
        cout<<sum_d<<endl;;
        return 0;
    
    }    
    for(int i=1;i<=N.size();i++){
        sum_d=0;
        REP(j,N.size()){
            if(j<i){
                sum_d+=N[j]-'0'-1;
            }else{
                sum_d+=9;
            }    
        }
        ans=max(ans,sum_d);
    }    
    print<ll>(ans);
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include<deque>
#include<vector>
#include<map>
#include<iterator>
#include<utility>
#include<algorithm>
#include<bitset>
#include<set>
 
 
 
 
using namespace std;
 
typedef long long ll;
 
int main() {
 
	int n; cin >> n;
	vector<ll>camels(n);
	set<ll>xo;
	for (int i = 0; i < n; i++) {
		ll j; cin >> j;
		camels[i] = j;
		xo.insert(j);
	}
	bool b = true;
 
	sort(camels.begin(), camels.end());
	if (n % 3 == 0) {
 
		for (ll i = 0; i < n; i = i + n / 3) {
			set <ll> gquiz1;
			for (int j = 0; j < n / 3; j++) {
				gquiz1.insert(camels[i + j]);
 
			}
 
			if (gquiz1.size() > 1) {
				b = false;
				break;
			}
 
		}
 
 
 
 
 
		if (xo.size() == 1) {
			if (camels[0] == 0) {
				cout << "Yes";
			}
			else{
				cout<<"No";
			}
		}
		else if (xo.size() == 2 && b) {
			ll num = 0;
			for (int i = 0; i < camels.size(); i++) {
				if (camels[i] == 0) {
					num++;
				}
			}
			if (num == n / 3) {
				cout << "Yes";
			}
			else {
				cout << "No";
			}
		}
		else if (xo.size() == 3 &&b) {
			
			vector<string>binary(3);
			ll maxlen = 0; int index=0;
			for (auto itr = xo.begin() ; itr!=xo.end() ; itr++) {
				string bin = bitset<64>(*itr).to_string();
				binary[index] = bin;
				index++;
				ll binsize = 0;
				for (ll j = 0; j < 64; j++) {
					if (bin[j] == '1') {
						binsize = 64 - j;
						break;
					}
				}
				if (binsize >= maxlen) {
					maxlen = binsize;
				}
			}
 
			vector<int>counting(64, 0);
			for (int i = 0; i < 3; i++) {
				for (int j = 63; j >= 64 - maxlen; j--) {
					if (binary[i][j] == '1') {
						counting[j]++;
					}
				}
			}
			bool ans = true;
			for (int i = 63; i >= 64 - maxlen; i--) {
				
				if (counting[i] != 2 && counting [i]!=0) {
					ans = false;
				}
 
			}
 
			if (ans) {
				cout << "Yes";
			}
			else {
				cout << "No";
			}
		}
		else {
			cout << "No";
		}
	}
 
	else {
		if (xo.size() == 1) {
			if (camels[0] == 0) {
				cout << "Yes";
			}
		}
		else {
			cout << "No";
		}
	}
	int l ; cin>>l;
	
}

Measured memory_bytes: 5632
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
using namespace std;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define nl printf("\n")
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli, lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
lli f(lli n)
{
    lli cnt=0;
    while(n)
    {
        cnt++;
        n/=10;
    }
    return cnt;
}
int main()
{
    opt;
    lli n,i,j,ans=100000000000,temp;
    cin>>n;
    rep(i,1,1+sqrt(n))
    {
        if(n%i==0)
        {
            temp=max(f(i),f(n/i));
            ans=min(ans,temp);
        }
    }
    cout<<ans;
}




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

int main(){
	string s1, s2;
	char c;
	cin >> s1 >> s2;
	string ans = "No";
	for(int i=0; i<s1.length(); i++){
		if(s1 == s2){
			ans = "Yes";
			break;
		}
		c = s1.back();
		s1.pop_back();
		s1.insert(s1.begin(), c);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	int N, a[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	cout << a[N - 1] - a[0] << endl;
}

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

const int inf = 1000000000;

int h, w;
vector<vector<int>> maze(1004, vector<int>(1004, -1));

queue<pair<int, int>> bfs_q;
queue<pair<int, int>> dfs_q;

void dfs(int i, int j)
{
  bfs_q.emplace(i, j);

  array<int, 4> di = {0, 1, 0, -1};
  array<int, 4> dj = {1, 0, -1, 0};

  int m = maze.at(i).at(j);

  for (int k = 0; k < 4; k++) {
    int ni = i + di.at(k);
    int nj = j + dj.at(k);
    if (maze.at(ni).at(nj) > m) {
      maze.at(ni).at(nj) = m;
      dfs(ni, nj);
    }
  }
}

int main()
{
  int si, sj, gi, gj;

  cin >> h >> w;
  cin >> si >> sj;
  cin >> gi >> gj;

  si++; sj++; gi++; gj++;

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      maze.at(i + 2).at(j + 2) = s.at(j) == '#' ? -1 : inf;
    }
  }

  maze.at(si).at(sj) = 0;
  dfs_q.emplace(si, sj);

  while (!empty(dfs_q) || !empty(bfs_q)) {
    while (!empty(dfs_q)) {
      auto [i, j] = dfs_q.front();
      dfs_q.pop();
      dfs(i, j);
    }
    while (!empty(bfs_q)) {
      auto [i, j] = bfs_q.front();
      bfs_q.pop();
      for (int di = -2; di <= 2; di++) {
        for (int dj = -2; dj <= 2; dj++) {
          int ni = i + di;
          int nj = j + dj;
          int m = maze.at(i).at(j);
          if (maze.at(ni).at(nj) > m + 1) {
            maze.at(ni).at(nj) = m + 1;
            dfs_q.emplace(ni, nj);
          }
        }
      }
    }
  }
  if (maze.at(gi).at(gj) == inf) maze.at(gi).at(gj) = -1;
  cout << maze.at(gi).at(gj) << endl;
}


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

int const N = 200000;
char s[N + 1];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	f(i, 0, n)if (s[i] == '?')s[i] = 'D';
	printf("%s\n", s);
}

Measured memory_bytes: 3848
from collections import defaultdict, Counter


def main():
    N = int(input())
    A = map(int, input().split())

    ans = AC(N, A)
    print(ans)


def AC(N, A):
    """
    差分のとり方を用意しておく
    報告に問題があるか調べる
    差分のとり方＝組合せの要素になる
    """
    diff_dict = defaultdict(int)
    for i in range(1, N + 1):
        left, right = i - 1, N - i
        diff = abs(left - right)
        diff_dict[diff] += 1

    c = Counter(A)
    if diff_dict != c:
        return 0

    ans = 1
    for count in c.values():
        ans = (ans * count) % (10 ** 9 + 7)

    return ans

if __name__ == '__main__':
    main()


Measured memory_bytes: 22624
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

struct rect {
	ll hei; ll pos;
};

ll const MAX = 3e3 + 3;
ll dp[MAX][MAX] = {};
string s, t;
vector<char> ans;
int main() {
	cin >> s >> t;
	ll n = s.size();
	ll m = t.size();
	REP(i, 1, n) {
		REP(j, 1, m) {
			if (s[i - 1] != t[j - 1]) {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
			else {
				dp[i][j] = max({ dp[i - 1][j], dp[i][j - 1],dp[i - 1][j - 1] + 1 });

			}
		}
	}
	ll i = n; ll j = m;
	while (i != 0 && j != 0) {
		if (s[i - 1] == t[j - 1] && dp[i][j] - dp[i - 1][j - 1] == 1) {
			ans.push_back(s[i - 1]);
			i--;
			j--;
		}
		else {
			if (dp[i][j] == dp[i - 1][j]) {
				i--;
			}
			else {
				j--;
			}
		}
	}
	PER(iii, SIZE(ans) - 1, 0) {
		cout << ans[iii];
	}
	cout << endl;

}

Measured memory_bytes: 70656
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}p; 

p Q[LEN];
int head, tail, n;

void enqueue(p x){
	Q[tail]=x;
	tail = (tail+1)%LEN;
}

p dequeue(){
	p x = Q[head];
	head = (head+1) % LEN;
	return x;
}

int min(int x, int y){
	return x < y ? x : y;
}

int main()
{
	int i,q,c,elaps=0;
	p u;
	scanf("%d %d",&n, &q);
	for(i=1;i<=n;i++)
	{
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head =1;
	tail=n+1;
	while(head!=tail)
	{
		u=dequeue();
		c=min(q,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0)
		enqueue(u);
		else
		printf("%s %d\n",u.name,elaps);
	}
	return 0;
}


Measured memory_bytes: 11892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    const ll mod=1e9+7;
    int n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];

    }
    vector<ll>suffix(n);
    suffix[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        suffix[i]=(suffix[i+1]+arr[i+1])%mod;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ans=(ans+((arr[i]*suffix[i])%mod))%mod;

    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 6424
n, k = gets.chomp.split(" ").map(&:to_i)
h = gets.chomp.split(" ").map(&:to_i)

dp = Array.new(n, 0)
dp[0] = 0
dp[1] = (h[1] - h[0]).abs

for i in 2..n - 1
    min = Float::INFINITY
    for j in 1..k
        if i - j < 0
            break
        end
        
        cost = dp[i - j] + (h[i] - h[i - j]).abs
    
        if cost < min
            min = cost
        end
    end
    dp[i] = min
end

puts dp[n - 1]

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

int main() {
  int N,A,B;
  cin >> N >>A >>B;
  int p,count;
  p=0;
  count=0;
  for(int i=1;i<=N;i++){
    if(i<10){
      p=i;
    }
    else if(i<100){
      p=i/10+i%10;
    }
    else if(i<1000){
      p=i/100+(i%100)/10+i%10;
    }
    else if(i<10000){
      p=i/1000+(i%1000)/100+(i%100)/10+i%10;
    }
    else {
      p=1;
    }
    if(p>=A && p<=B){
      count+=i;
    }
  }
  cout << count <<endl;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b;
    Scd2(a,b);

    if( a+b >= 10)
        printf ("error\n");
    else
        printf ("%d\n", a+b);

    return 0;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

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

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    for(ll i=K; i<=N+1; i++){
        ll mini;
        mini = ((0+i-1)*i)/2;
        // for(ll j=0; j<i; j++){
        //     mini += j;
        //     mini = mini % MOD;
        // }
        ll maxi;
        maxi = ((N-i+1+N)*i)/2;
        // for(ll j=N-i+1; j<=N; j++){
        //     maxi += j;
        //     maxi = maxi % MOD;
        // }
        ans += (maxi - mini + 1);
        ans = ans % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
fun main(args: Array<String>) {
    abc000X()
}

fun abc000X() {
    val s = readLine()!!
    if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
        println("No")
    }else if (s[0] == s[1] && s[2] == s[3]
        || s[0] == s[2] && s[1] == s[3]
        || s[0] == s[3] && s[1] == s[2]
    ) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 31660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline int updiv(int a, int b){return((a+b-1) / b);}

int main()
{
    FAST();
    int N, a;
    int ans = INT_MIN;
    int minv = INT_MAX;
    cin >> N;
    rep(i, N){
        cin >> a;
        chmax(ans, a - minv);
        chmin(minv, a);
    }
    outl( ans );
}

Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <deque>
#include <algorithm>

using namespace std;

int main(){
	int n, largest, exception, largest_index;
	
	cin >> n;
	deque<int> arr(n);
	
	for(int i=0;i<n;i++)
		cin >> arr[i];
	deque<int> tmp(arr);
	sort(tmp.begin(), tmp.end());
	largest = tmp[n-1];
	exception = tmp[n-2];
	
	for(int i=0;i<n;i++){
		if(arr[i]==largest){
			largest_index = i;
			break;
		}
	}
	for(int i=0;i<n;i++){
		if(i==largest_index){
			cout << exception << endl;
		}
		else{
			cout << largest << endl;
		}
	}
		
	
	return 0;
}

Measured memory_bytes: 3200
k = int(input())
val = 7
visited = set()
counter = 1
while len(visited) < k:
    val %= k
    if val in visited:
        print(-1)
        break
    elif val % k == 0:
        print(counter)
        break
    else:
        visited.add(val)
        val = (val * 10 + 7) % k
        counter += 1

Measured memory_bytes: 201208
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL MaxN = 1 + 1e5;

LL n, x, y, deg[MaxN], kq[MaxN], ans, vis[MaxN], ma;
vector<LL> q[MaxN];
priority_queue<LL> pq;

void DFS(LL u){
    vis[u] = 1;
    kq[u] = pq.top();
    pq.pop();
    for(int v : q[u])
    if(!vis[v]){
        DFS(v);
    }
}

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 0 ; i < n - 1 ; ++i){
        cin >> x >> y;
        q[x].push_back(y);
        q[y].push_back(x);
        deg[x]++;
        deg[y]++;
        if(deg[x] > deg[ma]) ma = x;
        if(deg[y] > deg[ma]) ma = y;
    }
    for(int i = 0 ; i < n ; ++i){
        cin >> x;
        pq.push(x);
        ans += x;
    }
    ans -= pq.top();
    DFS(ma);
    cout << ans << endl;
    for(int i = 1 ; i <= n ; ++i) cout << kq[i] << " ";

    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<math.h>
int main (){
	int a,b,l;
	scanf("%d %d",&a,&b);
	if (a>b){
		l=a;
	}
	else l=b;
	int k,c;
	c=0;
	for (k=0;k<l;k++){
		if (abs(a-k)==abs(b-k)){
			printf("%d\n",k);
			k=l;
			c=1;
		}
	}
	if (c==0){
		printf("IMPOSSIBLE\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define w(e) int e ; cin >> e ; while (e--)  
#define ll long long 
#define endl "\n"
#define mod  10000000007
#define pi 3.1415926535897932384626433
#define setbit(x) __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)  
/*
*/
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int l;
    cin >> l;
    long double ans = (l / 3.0) * (l / 3.0) * (l / 3.0);
    cout << fixed << setprecision(7) << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define hell  1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb   push_back


int main()
{
	ios;
	ll x,y;
	cin>>x>>y;
	ll mx=y/2,mn=(y/4)+(y%4)/2;
	if(y%2==1)cout<<"No";
	else if(x<=mx && x>=mn)cout<<"Yes";
	else cout<<"No";
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll H, W, K;
string S[15];

ll solve(ll b) {
    ll d = 1;
    REP(i, H) {
        if ((b >> i) & 1)
            d++;
    }
    vector<ll> v(d, 0);

    ll ret = d - 1;
    REP(w, W) {
        ll m = 0;
        ll index = 0;
        vector<ll> u(d, 0);
        REP(h, H) {
            if (S[h][w] == '1')
                m = std::max(m, (++u[index]) + v[index]);
            if ((b >> h) & 1)
                index++;
        }

        if (m > K) {
            REP(i, v.size()) {
                if (u[i] > K)
                    return INF;
                v[i] = 0;
            }
            ret++;
        }
        REP(i, u.size()) {
            v[i] += u[i];
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    REP(i, H) {
        cin >> S[i];
    }

    ll ans = INF;
    REP(b, pow(2, H - 1)) {
        ans = std::min(ans, solve(b));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
const ll MOD = 1000000007;
int dp[100000 + 100] = {INF};
int main() {
  ll N, M;
  cin >> N >> M;
  unordered_map<int, int> up;
  REP(i, M) {
    int a;
    cin >> a;
    up[a]++;
  }
  dp[0] = 1;
  REP(i, N) {
    if (up[i + 1] == 0) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD;
    }
    if (up[i + 2] == 0) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= MOD;
    }
  }
  if (dp[N] == INF) {
    cout << 0 << endl;
    return 0;
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 7892
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = inf;
    rep(i,101){
        int now = 0;
        rep(j,n){
            now += abs(i - v[j])*abs(i - v[j]);
        }
        ans = min(ans,now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> C(N,0),S(N,0),F(N,0);
    for(int i = 0;i < N-1;i ++){
        cin >> C[i] >> S[i] >> F[i];
    }
    for(int i = 0;i < N-1;i ++){
        int time = 0;
        time += S[i]+C[i];
        for(int j = i;j < N-2;j ++){
            if(time<=S[j+1]) time = S[j+1] + C[j+1];
            else if((time-S[j+1])%F[j+1]!=0) time += F[j+1] - (time-S[j+1])%F[j+1]+C[j+1];
            else time += C[j+1];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
    
    return 0;
}



Measured memory_bytes: 256
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N;
int[] A, B;
long[] C;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new int[N - 1];
      B = new int[N - 1];
      foreach (i; 0 .. N - 1) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
      }
      C = new long[N];
      foreach (j; 0 .. N) {
        C[j] = readLong();
      }
      C.sort();
      
      auto graph = new int[][N];
      foreach (i; 0 .. N - 1) {
        graph[A[i]] ~= B[i];
        graph[B[i]] ~= A[i];
      }
      auto deg = new int[N];
      foreach (u; 0 .. N) {
        deg[u] = cast(int)(graph[u].length);
      }
      
      alias Entry = Tuple!(int, "deg", int, "u");
      auto q = new RedBlackTree!Entry();
      foreach (u; 0 .. N) {
        q.insert(Entry(deg[u], u));
      }
      auto vis = new bool[N];
      long sum;
      auto ans = new long[N];
      foreach (j; 0 .. N) {
        const u = q.front.u;
        q.removeFront;
        vis[u] = true;
        sum += deg[u] * C[j];
        ans[u] = C[j];
        foreach (v; graph[u]) {
          if (!vis[v]) {
            q.removeKey(Entry(deg[v], v));
            --deg[v];
            q.insert(Entry(deg[v], v));
          }
        }
      }
      writeln(sum);
      foreach (u; 0 .. N) {
        if (u > 0) {
          write(" ");
        }
        write(ans[u]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 4476
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 1000000007;
string s[105];
signed main() {
	int h, w;
	cin >> h >> w;
	rep(i, h) {
		cin >> s[i];
		cout << s[i] << endl;
		cout << s[i] << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
const lli mod = (lli)(1e9 + 7);

lli n, a, b, ar[N], la[N], lb[N], tree[N << 2][2], lazy[N << 2][2];

void push(lli ind, lli x, lli y, lli idx) {
	if(lazy[ind][idx] != -1) {
		tree[ind][idx] = lazy[ind][idx];
		if(x != y) {
			lazy[left][idx] = lazy[ind][idx];
			lazy[right][idx] = lazy[ind][idx];
		}
		lazy[ind][idx] = -1;
	}
}

void clear(lli idx) {
	push(1, 0, n, idx);
	lazy[1][idx] = 0;
	push(1, 0, n, idx);
}

void upd(lli ind, lli x, lli y, lli a, lli val, lli idx) {
	push(ind, x, y, idx);
	if(a < x || y < a)
		return;
	if(x == y && x == a) {
		tree[ind][idx] += val;
		return;
	}
	upd(left, x, mid, a, val, idx);
	upd(right, mid + 1, y, a, val, idx);
	tree[ind][idx] = (tree[left][idx] + tree[right][idx]) % mod;
}

lli get(lli ind, lli x, lli y, lli a, lli b, lli idx) {
	push(ind, x, y, idx);
	if(a <= x && y <= b)
		return tree[ind][idx];
	if(y < a || b < x)
		return 0;
	return (get(left, x, mid, a, b, idx) + get(right, mid + 1, y, a, b, idx)) % mod;
}

signed main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	memset(lazy, -1, sizeof lazy);
	cin >> n >> a >> b;
	for(lli i = 1; i <= n; i++)
		cin >> ar[i];

	lli ind1 = 0, ind2 = 0;
	ar[0] = -1e18;
	for(lli i = 2; i <= n; i++) {
		while(ind1 < i && ar[i] - ar[ind1] >= a)
			ind1++;
		while(ind2 < i && ar[i] - ar[ind2] >= b)
			ind2++;
		la[i] = ind1 - 1;
		lb[i] = ind2 - 1;
	}
	ar[0] = ar[1];
	upd(1, 0, n, 0, 1, 0);
	upd(1, 0, n, 0, 1, 1);
	for(lli i = 1; i < n; i++) {
		lli addx = get(1, 0, n, 0, la[i + 1], 1), addy = get(1, 0, n, 0, lb[i + 1], 0);
		lli dpx = get(1, 0, n, 0, i, 0), dpy = get(1, 0, n, 0, i, 1);
		if(ar[i + 1] - ar[i] >= a)
			upd(1, 0, n, i, addx, 0);
		else {
			clear(0);
			upd(1, 0, n, i, addx, 0);
		}
		if(ar[i + 1] - ar[i] >= b)
			upd(1, 0, n, i, addy, 1);
		else {
			clear(1);
			upd(1, 0, n, i, addy, 1);
		}
	}
	cout << (get(1, 0, n, 0, n, 0) + get(1, 0, n, 0, n, 1)) % mod;
}

Measured memory_bytes: 78080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if(a == 2){cout << -1 << endl;}
  else if(a == 3){cout << "aa." <<endl;
                 cout << "..a" <<endl;
                 cout << "..a" <<endl;}
  else{
    int c;
    c = (a/4-1)*4;
    for(int i = 0;i < c/2;i++){
      for(int j = 0;j < c;j++){
      if(j/2==i){cout << 'a';}
      else if(j==c-2*i-2){cout << 'c';}
      else if(j==c-2*i-1){cout << 'd';}
        else{cout << '.';}
      }
      for(int j = 0;j < a-c;j++){
        cout << '.';}
      cout << endl;
      for(int j = 0;j < c;j++){
      if(j/2==i){cout << 'b';}
      else if(j==c-2*i-2){cout << 'c';}
      else if(j==c-2*i-1){cout << 'd';}
        else{cout << '.';}
      }
      for(int j = 0;j < a-c;j++){
        cout << '.';}
       cout << endl;
    }
    int p = a-c;
    if(p == 4){
      for(int i = 0;i < c;i++){cout << '.';}
      cout << "aabc" << endl;
      for(int i = 0;i < c;i++){cout << '.';}
      cout << "ddbc" << endl;
      for(int i = 0;i < c;i++){cout << '.';}
      cout << "bcaa" << endl;
       for(int i = 0;i < c;i++){cout << '.';}
      cout << "bcdd" << endl;}
    else if(p == 5){
      for(int i = 0;i < c;i++){cout << '.';}cout << "aabbc" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "de..c" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "de..f" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "h.ggf" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "hiijj" << endl;}
    else if(p==6){
      for(int i = 0;i < c;i++){cout << '.';}cout << "aabxx." << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "c.b..z" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "cdd..z" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "xx.aab" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "..zc.b" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "..zcdd" << endl;}
    else{
      for(int i = 0;i < c;i++){cout << '.';}cout << "aa.bb.c" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << ".d..eec" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "fdg...." << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "f.g...h" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "...iijh" << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "zxx..j." << endl;
      for(int i = 0;i < c;i++){cout << '.';}cout << "z.mm.nn" << endl;}
  }
}

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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    
    bool same = true;
    if (s.size() < t.size()) {
        for (size_t i=0; i<s.size(); ++i) {
            if (s[i] != t[i]) {
                same = false;
            }
        }
        if (same) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    for (size_t i=0; i<t.size(); ++i) {
        if (t[i]>s[0]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

Measured memory_bytes: 1792
import java.util.*

val sc = Scanner(System.`in`)
val H = sc.nextInt()
val W = sc.nextInt()

fun main(args: Array<String>) {
    val a = Array(H) { "" }
    for (i in 1..H) {
        a[i - 1] = sc.next()
    }
    for (i in 0..H + 1) {
        print("#")
        if (i in 1..H) {
            print(a[i - 1])
        } else {
            print("#".repeat(W))
        }
        println("#")
    }
}


Measured memory_bytes: 29352