akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=2005;

int num[maxn][maxn];

int main()
{
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n-1;j++)
		{
			scanf("%d",&num[i][j]);
		}
		num[i][0]=1; 
	}
	
	int cnt=n*(n-1)/2;
	
	int ans=0;
	
	int flag1=0;
	
	while(1)
	{
		ans++;
		
		int book[1005]={0};
		
		int flag2=0,now2;
		
		for(int i=1;i<=n;i++)
		{
			if(num[i][0]==n)//用完了 
				continue; 
			
			now2=num[i][num[i][0]];
			
			if(cnt>0&&book[i]==0&&book[now2]==0&&num[now2][num[now2][0]]==i)
			{
				num[i][0]++;
				num[now2][0]++;
				book[i]=1;
				book[now2]=1;
				cnt--;
				flag2=1;
			}
		}
		
		if(flag2==0)
		{
			flag1=1;
			break;
		}
		
		if(cnt==0)
			break;
	}
	
	if(flag1==1)
	{
		printf("-1\n");
		return 0;
	}
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 8448
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ');
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  let left, right, largest;
  const maxHeapify = (i) => {
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[i])) largest = left;
    else largest = i;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2 - 1); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 110524
# -*- coding:utf-8 -*-
"""解説
2019で割った余りが同じであるような2数a, bにおいて、

a * c mod 2019
b * c mod 2019

は同じ値になる。

今求めたいのは、

(i*j) ≡ x (mod 2019)

のxの最小値である。

(例)
L=2020のとき、
mod 2019の世界では、2020は1と等価

よって、
2020 * 2021 は、
1 * 2 と等価

つまり、

(i*j) ≡ x (mod 2019) は、

(i%2019) * (j%2019) ≡ x (mod 2019) と同じ

そう考えると、i, jの調べる範囲は、

L%2019 ≦ i < j ≦ min(R, (L+2019)%2019)

なぜL+2019かというと、 mod2019の1周分の範囲を取れば、必ず0をかけることができ、そのとき最小値0になるから。

よって、(i, j)として調べる候補はたかだか2019**2 であり、全探索で間に合う。
"""

def solve():
    L, R = list(map(int, input().split()))
    MOD = 2019

    if R-L >= MOD:
        print(0)
        return

    L %= MOD
    R %= MOD
    ans = MOD
    for i in range(L, R):
        for j in range(i+1, R+1):
            ans = min(ans, (i*j)%MOD)
            if ans == 0:
                print(ans)
                return
    print(ans)


if __name__ == "__main__":
    solve()


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

int main() {
  int a,b,c;
  cin >> a;
  b=a/10;
  c=a-b*10;
  if(b==9 || c==9){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl cout<<"\n"
#define fr(n) for(int i = 0; i<n; i++)
#define frr(j, n) for(int i = j; i<n; i++)
using namespace std;
typedef long long int lli;
int main(){
    int x, t, n;
    cin>>n>>x>>t;
    int k = ceil((float)n/x);
    cout<<k*t;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t,a=0,b=0;
    cin >> t;
    vector<int> v(t);
    for(int i=0;i<t;i++){
        cin >> v[i];
        //cout << v[i] << endl;
    }
    for(int i=t-1;i>0;i--){
        if(v[i]<=v[i-1])
            a++;
        else{
            if(a>b)
                b=a;
            a=0;
        }
        
    }
       if(a>b)
        b=a;
        cout << b<< endl;

}


Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] c = new int[4];
		int n = scan.nextInt();
		while(n-->0) {
			String s = scan.next();
			if(s.equals("AC"))
				c[0]++;
			else if(s.equals("WA"))
				c[1]++;
			else if(s.equals("TLE"))
				c[2]++;
			else 
				c[3]++;
		}
		System.out.println("AC x "+c[0]);
		System.out.println("WA x "+c[1]);
		System.out.println("TLE x "+c[2]);
		System.out.println("RE x "+c[3]);
	}

}


Measured memory_bytes: 48508
#define DEBUG 0

/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2/16/2019, 9:01:50 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
int X[100];

int main()
{
  cin >> N >> M;
  fill(X, X + M, 0);
  for (auto i = 0; i < N; i++)
  {
    int K;
    cin >> K;
    for (auto k = 0; k < K; k++)
    {
      int A;
      cin >> A;
      A--;
      X[A]++;
    }
  }
  int ans = 0;
  for (auto i = 0; i < M; i++)
  {
    if (X[i] == N)
    {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
  int N, a, cnt=0, cnt2=0;
  cin >> N;
  for(int i=1; i<=N; i++){
    if(i%2==0) continue;
    for(int j=1; j<=i; j++){
      if(i%j==0)cnt++;
      a=i;
    }
    if(cnt==8){
      cnt2++;
    }
    cnt=0;
  }
  cout << cnt2 << endl;
}

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;

int main() {
	long long x;
	cin >> x;
	long long ans = 0;

	if (x % 11 == 0) {
		ans = x / 11 * 2;
	}
	else if(x % 11 <= 6) {
		ans = x / 11 * 2 + 1;
	}
	else {
		ans = x / 11 * 2 + 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.InputStreamReader;
  
public class Main{
    public static void main(String args[])throws java.lang.Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        //変数に配列を代入
        int s =Integer.parseInt(line);
        int h = s / 3600;
        int m = (s % 3600) / 60;
        s = s % 60;
        System.out.println(h+":"+m+":"+s);
        
    }
}

Measured memory_bytes: 16864
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]

def main():
    n, k = read_h()
    l = sorted(read_h(), reverse=True)
    print(sum(l[:k]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
  string a,b;
  cin>>a>>b;
  a.push_back(b[a.size()]);
  if(a==b)cout<<"Yes";
  else cout<<"No";
  }


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

int main () {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++)
    cin >> blue.at(i);
  
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++)
    cin >> red.at(i);
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int b_sum = 0, r_sum = 0;
    for (int j = 0; j < N; j++) {
      if (blue.at(i) == blue.at(j))
        b_sum++;
    }
    for (int j = 0; j < M; j++) {
      if (blue.at(i) == red.at(j))
        r_sum++;
    }
    if (sum < b_sum - r_sum)
      sum = b_sum - r_sum;
  }
  
  for (int i = 0; i < M; i++) {
    int b_sum = 0, r_sum = 0;
    for (int j = 0; j < N; j++) {
      if (red.at(i) == blue.at(j))
        b_sum++;
    }
    for (int j = 0; j < M; j++) {
      if (red.at(i) == red.at(j))
        r_sum++;
    }
    if (sum < b_sum - r_sum)
      sum = b_sum - r_sum;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*ll t;cin>>t;
 while(t--)
  {*/
    ll i, flag=0;
   string s;cin>>s;
   for(i=0;i<s.length();i++)
    {
      if(s[i]=='7')
      flag=1;
      }
      if(flag==1)
      cout<<"Yes";
      else
      cout<<"No";
    
}    

Measured memory_bytes: 3612
import math


def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    index_one = A.index(1)
    min_cnt = N
    for left_index in range(index_one - (K - 1), index_one + 1):
        right_index = left_index + (K - 1)
        if left_index < 0 or right_index > N - 1:
            continue
        cnt = 1 + math.ceil(left_index / (K - 1)) + math.ceil((N - 1 - right_index) / (K - 1))
        min_cnt = min([min_cnt, cnt])
    print(min_cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13812
#include <iostream>
#include <set>

using namespace std;

int main()
{

    int n;
    cin >> n;
    set <string> str;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
       str.insert(s);


    }
    int counter = 0;
    for (int i = 0; i < str.size(); i++) {
        counter++;
    }

    cout <<  counter << endl;

return 0;

}


Measured memory_bytes: 19216
#include <stdio.h>
#include <string.h>
 
int main(){
   char s[100000];
   int k;
   int len,i;
 
   scanf("%s",s);
   scanf("%d",&k);
 
   len=strlen(s);
   for(i=0;i<len;++i){
      if((s[i]!='a')&&(('z'-s[i])<k)){
         k-=('z'-s[i]+1);
         s[i]='a';
      }
   }
   k%=26;
   if(k){
      s[len-1]=(((s[len-1]-'a')+k)%26)+'a';
   }
 
   printf("%s\n",s);
 
   return 0;
}


Measured memory_bytes: 384
N,M=[int(x) for x in input().rstrip().split()]
l=[]
for i in range(M):
  ks=[int(x) for x in input().rstrip().split()]
  l.append(ks)
p=[int(x) for x in input().rstrip().split()]
now_l=[False for i in range(N)]
ans=0

for i in range(2**N):
  for j in range(N):
    if i>>j & 1:
      now_l[j]=True
  cnt1=0
  for s in range(M):
    now=l[s]
    cnt=0
    for t in range(len(now)-1):
      if now_l[now[t+1]-1]==True:
        cnt+=1
    if cnt%2==p[s]:
      cnt1+=1
  if cnt1==M:
    ans+=1
  now_l=[False for b in range(N)]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    int n;
    cin>>n;
    vector<int>h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    int high=h[0]-1;
    bool flag=true;
    for(int i=1;i<n;i++){
        if(high==h[i]-1||high==h[i]){
            //hello('_')
        }
        else if(high<=h[i]-1){
            high=h[i]-1;
        }
        else{
            flag=false;
            break;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
 
int main(void)
{
 
  int x,y,d,tmp;
 
  scanf("%d%d",&x,&y);
 
  if(x<y){
    tmp = x;
    x = y;
    y = tmp;
  }
  d = x % y;
  while(d!=0){
    x = y;
    y = d;
    d = x % y;
  }
  printf("%d\n", y);
 
  return 0;
}



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

int main() {
	int n,i,k,x,cur=0,ans=0;
	cin >> n >> k;
	for(i=0; i<n; i++){
		cin >> x;
		ans+=2*min(x,k-x);
	}
	cout << ans;
}


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


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

    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<int> T(N, 0);
    for (int i = 1; i < N; i++) {
        T[i] += T[i - 1];
        if (S[i - 1] == 'A' && S[i] == 'C') T[i]++;
    }

    int l, r;
    rep(_, Q) {
        cin >> l >> r;
        cout << T[r - 1] - T[l - 1] << endl;;
    }

    return 0;
}

Measured memory_bytes: 3844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String text = in.next();
		int n = in.nextInt();
		int count = 0;
		while (n-- > 0) {
			String s;
			s = (s = in.next()) + s;
			count += (s.contains(text) ? 1 : 0);
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17220
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if(s.size()%2==1 and s.front()==s.back()){//abxyaba
		cout<<"Second"<<endl;
		return 0;
	}
	if(s.size()%2==0 and s.front()!=s.back()){//abxyab
		cout<<"Second"<<endl;
		return 0;
	}
	cout<<"First"<<endl;
	return 0;
}

Measured memory_bytes: 512
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n!=0){
        int sum = n % 10;
        if(sum == 7)
        {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}


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

int main(){
int N;
   cin>>N;
  
  for(int i=1; i<10; i++){
   if(N<111){cout<<i*100+i*10+i; return 0;}
   else if(N<=i*100+i*10+i){cout<<i*100+i*10+i; return 0;} 
  }
  
}

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

int main(){
  int n;
  vector<P> v;
  cin >> n;
  while(n--){
    int x,y;
    cin >> x >> y;
    v.push_back(P(x,y));
  }
  sort(v.begin(),v.end());
  r(i,v.size()){
    cout << v[i].first << " " << v[i].second <<endl;
  }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<string> s(n);
    rep(i, n) cin>>s[i];
    rep(i, n) sort(s[i].begin(), s[i].end());
    sort(s.begin(), s.end());

    ll ans = 1;
    ll num = 1;
    rep(i, n-1){
        if (s[i]==s[i+1]){
            num++;
        }else{
            ans+=num*(num-1);
            num = 1;
        }
    }
    ans += num*(num-1);
    cout << ans/2 << "\n";
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  double n;
  cin >> n;
  if(int(n) % 2 == 1){
    cout << (int(n / 2) + 1.0) / n << endl;
  }else{
    cout << 1.0 / 2.0 << endl;
  }

}


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

const int MAXN=100010;

void zout(long long a)
{
	if(a>9)
		zout(a/10);
	putchar(a%10+'0');
	return;
}

int main()
{
	char c[MAXN];
	long long win=0,p=0,g=0;
	int i=1;
	
	c[i]=getchar();
	while(c[i]=='p'||c[i]=='g')
		c[++i]=getchar();
	
	for(int j=1;j<=i;j++)
	{
		if(p+1<=g)
		{
			p++;
			if(c[j]=='g')
			win++;
		}
		else
		{
			g++;
			if(c[j]=='p')
			win--;
		}
	}
	zout(win);
	return 0;
}

Measured memory_bytes: 384
#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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second < b.second; });
    REP(i, N) {
        pll a;
        cin >> a.first >> a.second;
        q.push(a);
    }

    ll sum = 0;
    ll type = 0;
    map<ll, ll> m;
    priority_queue<ll, vector<ll>, greater<>> q0;
    REP(i, K) {
        pll t = q.top();
        q.pop();
        sum += t.second;
        if (m[t.first]++ == 0)
            type++;
        else
            q0.push(t.second);
    }

    vector<pll> v;
    while (!q.empty() && !q0.empty()) {
        pll t0 = q.top();
        q.pop();
        if (m[t0.first]++ > 0)
            continue;
        ll t1 = q0.top();
        q0.pop();
        pll p(0, 0);
        if (v.size() > 0)
            p = v.back();
        p.first += t0.second;
        p.second += t1;
        v.push_back(p);
    }

    ll ans = sum + type * type;
    REP(i, v.size()) {
        ans = std::max(ans, sum - v[i].second + v[i].first + (type + 1 + i) * (type + 1 + i));
    }

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

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll mod=1e+9+7;
int main(void){
    int n;string s;cin>>n>>s;
    map<char,int> mp;
    rep(i,n) mp[s[i]]++;
    ll res=1;
    for(auto& p:mp){
        res*=(p.second+1);
        res%=mod;
    }
    cout<<res-1<<endl;
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BVaried solver = new BVaried();
        solver.solve(1, in, out);
        out.close();
    }

    static class BVaried {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            out.println(s.length() > s.chars().distinct().count() ? "no" : "yes");
        }

    }
}



Measured memory_bytes: 28752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,ans;
    cin >>a>>b;
    if(a!=b){
    ans=max(a,b)+max(a-1,b-1);
    }else{
      ans=a*2;
    }
  cout<<ans<<endl;  
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long
#define ld long double

struct XX{
    int a;
    int b;
    ll c;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.a) == (riRight.a)){
            return riLeft.b > riRight.b;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.a) < (riRight.a);
    }
};

//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}

//int n;
////int dat[2*10000000];
////int dat2[2*10000000];
//int dat[10];
//int dat2[10];
//
//void init(int n_){
//    n=1;
//    while(n<n_)n*=2;
//    for(int i=0;i<2*n-1;i++){
//        dat[i]=0;
//        dat2[i]=0;
//    }
//}
//
//void initset(int k,int a){
//    k+=n-1;
//    dat[k]=a;
//    while(k>0){
//        k=(k-1)/2;
//        dat[k]=dat[k*2+1]+dat[k*2+2];
//    }
//}
//
////[a,b)の間を[l,r]区間で比較しアップデート
////引数のindexに注意
////nは固定。initで計算すみ
////update2(L[i],R[i]+1,0,0,n,D[i]);
//void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index
//    if(r<=a || b<=l)return;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=v*(r-l);
//        return;
//    }else{
//        update2(a,b,k*2+1,l,(l+r)/2,v);
//        update2(a,b,k*2+2,(l+r)/2,r,v);
//        return;
//    }
//}
//
//int query(int a,int b,int k,int l,int r){
//    if(r<=a || b<=l)return 0;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=0;
//        return dat[k];
//    }
//    else{
//        int vl=query(a,b,k*2+1,l,(l+r)/2);
//        int vr=query(a,b,k*2+2,(l+r)/2,r);
//        return vl+vr;
//    }
//}



int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs("3.txt");//テスト用
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A,B,C;
    cin >> B>>A>>C;
    ll ans=0;
    if(C<=A+B){
        ans=C;
        ans+=A;
    }else{
        if(C>=A+B){
            ans+=A+B+1;
        }else{
            ans+=C;
        }
        ans+=A;
    }
    cout << ans << endl;

    //ここまで
    //cout << "ans" << endl;
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    
    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn main(){
    let mut buf = String::new();
    
    let _ = io::stdin().read_line(&mut buf);
    let n = i64::from_str(buf.trim()).unwrap();
    
    for i in 3..n+1 {
        if three(i) {
            print!(" {}", i);
        }
    }
    println!();
}

fn three(n: i64) -> bool{
    if n%3 == 0 {
        return true;
    }

    let mut m = n;
    while m > 0 {
        if m%10 == 3 {
            return true;
        }
        m /= 10;
    }
    return false;
}




Measured memory_bytes: 5028
z=input()
l = len(z)
char_list =list(z)
for i in range(int (l)):
  if char_list[i]=="1":
    char_list[i]="9"
  elif char_list[i]=="9":
    char_list[i]="1"
s = ""
for i in range(int (l)):
  s=s+char_list[i]
print(s)
  


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<int>> vec(3,vector<int>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        if(vec.at(j).at(k) == x){
          vec.at(j).at(k) = -1;
        }
      }
    }
  }
  
  bool bingo = false;
  for(int i=0; i<3; i++){
    if(vec.at(i).at(0) == -1 && vec.at(i).at(1) == -1 && vec.at(i).at(2) == -1){
      bingo = true;
    }
  }
  for(int i=0; i<3; i++){
    if(vec.at(0).at(i) == -1 && vec.at(1).at(i) == -1 && vec.at(2).at(i) == -1){
      bingo = true;
    }
  }
  if(vec.at(0).at(0) == -1 && vec.at(1).at(1) == -1 && vec.at(2).at(2) == -1){
    bingo = true;
  }
  if(vec.at(0).at(2) == -1 && vec.at(1).at(1) == -1 && vec.at(2).at(0) == -1){
    bingo = true;
  }
  if(bingo){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, AC = 0, WA = 0, TLE = 0, RE = 0;
    scanf("%d", &n);
    while (n--) {
        char str[4];
        scanf("%s", str);
        if (str[0] == 'A') {
            AC++;
        }
        else if (str[0] == 'W') {
            WA++;
        }
        else if (str[0] == 'T') {
            TLE++;
        }
        else {
            RE++;
        }
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", AC, WA, TLE, RE);
    return 0;
}


Measured memory_bytes: 1732
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=a;i<(n);i++)
typedef long int li;


li combin(li n,li k){
  static int flag=1;
  static vector<li> fact(n+1,1),ifa(n+1,1),inv(n+1,1);
  if(flag){
    flag=0;
    repa(i,2,n+1){
      fact[i]=fact[i-1]*i%MOD;
      inv[i]=(MOD-(MOD/i))*inv[MOD%i]%MOD;
      ifa[i]=ifa[i-1]*inv[i]%MOD;
    }
    if(df){
      rep(i,n+1) printf("%ld ",fact[i]);
      printf("\n");
      rep(i,n+1) printf("%ld ",ifa[i]);
      printf("\n");
      rep(i,n+1) printf("%ld ",inv[i]);
      printf("\n");
    }
  }
  li s=fact[n]*ifa[k]%MOD;
  if(df)printf("C(%d,%d)=%d\n",n,k,s*ifa[n-k]%MOD);
  return s*ifa[n-k]%MOD;
}


int main(){
  if(df) printf("*debug mode*\n");
  li n,k; cin >>n >>k;
  if(k>=n) k=n-1;
  li ans=0;
  rep(i,k+1){
    li s=combin(n,i);
    s=s*combin(n-1,i)%MOD;
    if(df)printf("%d\n",s);
    (ans+=s)%=MOD;
  }
  cout << ans;
}

/// confirm df==0 ///


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

int main(){
	int N;
	cin>>N;
	vector<long>A(N);
	for(int i=0;i<N;++i)cin>>A[i];
	sort(A.begin(),A.end(),greater<int>());
	/*
	for(int i=0;i<N;++i){
		cout<<A[i]<<" ";
	}
	cout<<endl;
	*/
	int i=0;
	vector<long>bo;
	while(i<N && bo.size()<2){
		if(A[i]==A[i+1]){
			bo.push_back(A[i]);
			i+=2;
		}
		else i++;
	}
	if(bo.size()==2)cout<<bo[0]*bo[1]<<endl;
	else cout<<0<<endl;
}


Measured memory_bytes: 1024
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.append(0)

dif_1 = [0] * (N+1)
dif_2 = [0] * N

for i in range(N+1):
    dif_1[i] = abs(A[i] - A[i+1])

for i in range(N):
    dif_2[i] = abs(A[i] - A[i+2])

num = sum(dif_1)

for i in range(N):
    print(num - (dif_1[i] + dif_1[i+1]) + dif_2[i])


Measured memory_bytes: 16484
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    
    int a,b;
    
    int d,r;
    double f;
    
    cin >>a>>b;
    
    d = a / b;
    r = a % b;
    f = (double)a/b;
    
    printf("%d %d %f\n",d,r,f);
    
}



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

class Dice{
private:
  int right,left,front,back,bottom,now;
  void role(int num[6],string str){
    for(int i=0;i<str.size();i++){
      switch(str[i]){
      case 'S':num[1]=now;num[0]=back;num[4]=bottom;num[5]=front;now=num[0];back=num[4];bottom=num[5];front=num[1];break;
      case 'W':num[3]=now;num[5]=left;num[2]=bottom;num[0]=right;now=num[0];left=num[3];bottom=num[5];right=num[2];break;
      case 'E':num[3]=bottom;num[0]=left;num[2]=now;num[5]=right;now=num[0];left=num[3];bottom=num[5];right=num[2];break;
      case 'N':num[4]=now;num[0]=front;num[1]=bottom;num[5]=back;now=num[0];back=num[4];bottom=num[5];front=num[1];break;
      }
     
    }
  }
public:
  void Scan(int num[6],string str){
    now=num[0];right=num[2];left=num[3];front=num[1];back=num[4];bottom=num[5];
    role(num,str);
  }
};

int main(){
  Dice dice;
  string str;
  int num[6];
  for(int i=0;i<6;i++)
    cin>>num[i];
  cin>>str;
  dice.Scan(num,str);
  cout<<num[0]<<endl;
  return 0;
}

Measured memory_bytes: 3180
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef pair<P,P> Edge;
typedef long long ll;

const double PI=4*atan(1.0);

void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}
	

#ifdef RED_FILE
ifstream ifs("input.txt");
ofstream ofs("output.txt");
#define cin ifs
#define cout ofs
#endif


map<string,vector<string> > msn;

map<string,set<string> > dp;

set<string> dfs(string name){
    if(dp.find(name)!=dp.end())return dp[name];
    set<string> res;
    if(msn.find(name)==msn.end()){
        res.insert(name);
        return res;
    }
    for(int i = 0;i<msn[name].size();i++){
        set<string> tmp=dfs(msn[name][i]);
        for(set<string>::iterator it=tmp.begin();it!=tmp.end();it++)
            res.insert(*it);
    }
    return dp[name]=res;
}

int main(){

    int n;
    while(cin>>n&&n!=0){
        dp.clear();
        msn.clear();
        string s;
        vector<string> ns;
        for(int i=0;i<n;i++){
            cin>>s;
            string nodeName;
            for(int j=0;j<s.size();j++){
                if(s[j]==':'){
                    nodeName=s.substr(0,j);
                    s=s.substr(j+1);
                    break;
                }
            }
            ns.push_back(nodeName);
            int prv=0;
            vector<string> vs;
            for(int j=0;j<s.size();j++){
                if(s[j]==','||s[j]=='.'){
                    vs.push_back(s.substr(prv,j-prv));
                    prv=j+1;
                }
            }
            msn[nodeName]=vs;
        }
        int res=dfs(ns[0]).size();
        cout<<res<<endl;
    }


    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();

            if(a <= b && a <= c) {
                if(b <= c) System.out.println(a + " " + b + " " + c);
                else System.out.println(a + " " + c + " " + b);
            }else if(b <= a && b <= c){
                if(a <= c) System.out.println(b + " " + a + " " + c);
                else System.out.println(b + " " + c + " " + a);
            }else if(c <= a && c <= b){
                if(a <= b) System.out.println(c + " " + a + " " + b);
                else System.out.println(c + " " + b + " " + a);
            }
            
            sc.close();
        }
}


Measured memory_bytes: 26292
from sys import stdin
N=int(stdin.readline().rstrip())
data1=[int(x) for x in stdin.readline().rstrip().split()]
data2=[int(x) for x in stdin.readline().rstrip().split()]
sum1=0
sum2=0
ans=0
for i in range(N):
    calc=(sum(data1[0:i+1])+sum(data2[i:]))
    if calc > ans:
        ans=calc
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class ForStudy
    {
        public static void Main(string[] args)
        {
            var num = new int[26];
            string str;
            while ((str = Console.ReadLine())!=null)
            {
                if (str == "")
                {
                    break;
                }
                foreach (char c in str)
                {
                    if (char.IsUpper(c))
                    {
                        try
                        {
                            num[char.ToLower(c) - 'a']++;
                        }
                        catch
                        {

                        }

                    }
                    else
                    {
                        try
                        {
                            num[c - 'a']++;
                        }
                        catch
                        {

                        }
                    }
                }
            }

            for (int i = 0; i < 26; i++)
            {
                Console.WriteLine("{0} : {1}", (char)(i + (int)'a'), num[i]);
            }
        }
    }
}


Measured memory_bytes: 15824
N, K = list(map(int, input().split()))
S = list(input())

ans = 0
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += 1
    if S[i] != S[i+1]:
        count += 1

while count > 0 and K > 0:
    if count == 1:
        count -= 1
        ans += 1
        K -= 1
    else:
        K -= 1
        count -= 2
        ans += 2

print(ans)



Measured memory_bytes: 4084
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := nextStr()
	color := strings.Split(s, "")

	//条件1に該当する組み合わせ
	r, g, b := 0, 0, 0
	for i := range color {
		switch color[i] {
		case "R":
			r++
		case "G":
			g++
		case "B":
			b++
		}
	}

	//条件2に該当する組み合わせ
	ex := 0
	for i := 0; i < n-1; i++ {
		for j := i+1; 2*j-i < n; j++ {
			if color[i] != color[j] && color[j] != color[2*j-i] && color[2*j-i] != color[i] {
				ex++
			}
		}
	}
	fmt.Println(r*g*b-ex)
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
int main(){

Vec vec(9);
for(int i=0;i<9;i++){
    cin>>vec[i];
}
int n,x;
cin>>n;
for(int i=0;i<n;i++){
    cin>>x;
    for(int j=0;j<9;j++){
        if(vec[j]==x){
            vec[j]=0;
        }
    } 
}
bool xz=false;
if(vec[0]==0&&vec[4]==0&&vec[8]==0){
   xz=true;
}
if(vec[2]==0&&vec[4]==0&&vec[6]==0){
   xz=true;
}
for(int i=0;i<7;i+=3){
    if(vec[i]==0&&vec[i+1]==0&&vec[i+2]==0){
   xz=true;
    }
}
for(int i=0;i<3;i++){
    if(vec[i]==0&&vec[i+3]==0&&vec[i+6]==0){
   xz=true;
    }
}
if(xz){
    cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;


}

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

struct node {
    struct node* prev;
    struct node* next;
    int key;
};

struct node* head = NULL;
struct node* tail = NULL;


static void insert(int key) {
    struct node *node;
    node = malloc(sizeof(struct node));
    node->key = key;
    
    if ( head == NULL ) {
        head = tail = node;
        node->prev = node->next = NULL;
    } else {
        node->next = head;
        head->prev = node;
        head = node;
    }
    return;
}

static void deleteFirst(void) {
    struct node* node;
    if ( !head ) {
        return;
    }
    if ( head == tail ) {
        node = head;
        head = tail = NULL;
    } else {
        head->next->prev = NULL;
        node = head;
        head = head->next;
    }

    free(node);

    return;
}

static void deleteLast(void) {
    struct node* node;
    if ( !tail ) {
        return;
    }
    if ( head == tail ) {
        node = head;
        head = tail = NULL;
    } else {
        tail->prev->next = NULL;
        node = tail;
        tail = tail->prev;
    }

    free(node);

    return;
}

static int delete(int key) {
    struct node* node;
    int ret = 0;

    for ( node = head; node != NULL; node = node->next) {
        if ( node->key == key ) {
            if ( node == head ) {
                deleteFirst();
            } else if ( node == tail ) {
                deleteLast();
            } else {
                node->prev->next = node->next;
                node->next->prev = node->prev;
                free(node);
            }
            return 1;
        }
    }

    return 0;
}

static void printAndDeleteList(void) {
    struct node* node;

    while ( head ) {
        printf("%d", head->key);
        deleteFirst();
        if ( head ) {
            printf(" ");
        }
    }

    printf("\n");

    return;
}
 
int main(int argc, char* argv[]) {
    int i, n;
    char buf[20];
    int key;

    scanf("%d\n", &n);

    for ( i = 0; i < n; i++ ) {
        scanf("%s %d\n", buf, &key);

        if ( strcmp("insert", buf) == 0 ) {
            insert(key);
        } else if ( strcmp("delete", buf) == 0 ) {
            delete(key);
        } else if ( strcmp("deleteFirst", buf) == 0 ) {
            deleteFirst();
        } else if ( strcmp("deleteLast", buf) == 0 ) {
            deleteLast();
        }
    }

    printAndDeleteList();

    return 0;
}



Measured memory_bytes: 33040
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

const int M = 10000;

int n, a[M], b[M], c[M], ans[M], cnt;
vector<int> g[M];

void dfs(int v, int p) {
	ans[v] = c[cnt++];
	RF(e, g[v]) {
		if(e == p) { continue; }
		dfs(e, v);
	}
}

int main() {
	cin >> n;
	inc(i, n - 1) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		g[a[i]].PB(b[i]);
		g[b[i]].PB(a[i]);
	}
	inc(i, n) { cin >> c[i]; }
	sort(c, c + n);
	reverse(c, c + n);
	
	dfs(0, -1);
	
	int s = 0;
	inc(i, n - 1) { s += min(ans[a[i]], ans[b[i]]); }
	cout << s << endl;
	inc(i, n) { cout << (i == 0 ? "" : " ") << ans[i]; }
	cout << endl;
	
	return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
vector <int> P;
char C[5] = {' ', 'A', 'G', 'C', 'T'};
ll DP[105][1000];

char now[4];
string S[3] = {"AGC", "GAC", "ACG"};
int DFS(int num, int turn){
  if (turn == 4){
    bool flag = false;
    if (now[0] == 'A' && now[2] == 'G' && now[3] == 'C') flag = true;
    if (now[0] == 'A' && now[1] == 'G' && now[3] == 'C') flag = true;

    for (int i = 0; i < 2; i++){
      string res = "";
      for (int j = 0; j < 3; j++){
        res += now[i + j];
      }
      for (int j = 0; j < 3; j++){
        if (res == S[j]) flag = true;
      }
    }
    if (flag) {
      P.push_back(num);
    }
    return 0;
  }

  for (int i = 0; i < 5; i++){
    now[turn] = C[i];
    DFS(num * 5 + i, turn + 1);
  }
  return 0;
}

int main(){
  cin >> N;
  DP[0][0] = 1;
  DFS(0, 0);

  for (int i = 1; i <= N; i++){
    for (int j = 0; j < 625; j++){
      for (int k = 1; k <= 4; k++){
        DP[i][(j%125)*5+k] += DP[i-1][j];
        DP[i][(j%125)*5+k] %= MOD;
      }
    }
    for (int j = 0; j < P.size(); j++){
      DP[i][P[j]] = 0;
    }
  }

  ll ans = 0;
  for (int j = 0; j < 625; j++){
    ans += DP[N][j];
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4368
// C - Many Medians

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int X[200000];
int sX[200000];

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

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

	sort(sX, sX+N);
	int L = sX[N/2 - 1];
	int R = sX[N/2];

	for (int i=0; i<N; i++) {
		if (X[i] <= L) cout << R << endl;
		else cout << L << endl;
	}

	return 0;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
    cin >> n >> s;
    int l = 0, r = 0;
    for(int i = 0; i < n; ++i) {
        if(s.at(i) == '(') l++;
        else {
            if(l > 0) l--;
            else r++;
        }
    }
    for(int i = 0; i < r; ++i) cout << '(';
    cout << s;
    for(int i = 0; i < l; ++i) cout << ')';
}

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

int main(void){ 
    int n; cin >> n;
    vector<string>s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
        // cout << s[i] << endl;
        sort(s[i].begin(),s[i].end());
        // cout << s[i] << endl;
    }
    sort(s.begin(),s.end());

    // for(int i=0;i<n;i++){
    //     cout << s[i] << endl;
    // }

    ll cnt=1,ans=0;
    for(int i=0;i<=n-1;i++){
        if(i!= n-1 && s[i]==s[i+1]){
            cnt++;
        } 
        else{
            ans += cnt*max(1,int(cnt-1))/2;
            cnt=1;
        } 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int N, M, D[100010]; 
int INF = 1145141919; 
pair<int, int> A[100010]; 
vector<int> E[100010]; 
map<pair<int, int>, int> mp;
vector<int> ans;  
bool seen[100010];
void dfs(int i, int p){
	if(seen[i]) return; 
	seen[i] = true; 
	for(int j = 0; j < E[i].size(); j++){
		if(seen[E[i].at(j)]) continue; 
		dfs(E[i].at(j), i); 
	}
	if(D[i] % 2){
		D[i] ++; D[p] ++; 
		ans.emplace_back(mp[make_pair(i, p)]); 
	}
}
int main(){
	cin >> N >> M; 	
	for(int i = 0; i < N; i++){
		cin >> A[i].first >> A[i].second; 
	}
	A[N].first = -INF; A[N].second = 0; 
	A[N+1].first = INF; A[N+1].second = 0; 
	sort(A, A+N+2); 
	for(int i = 0; i < N+1; i++){
		D[i] = (A[i+1].second ^ A[i].second); 
	}
	for(int i = 0; i < M; i++){
		int L, R; cin >> L >> R; 
		int a = lower_bound(A, A+N+2, make_pair(L, 0)) - A - 1; 
		int b = upper_bound(A, A+N+2, make_pair(R, 2)) - A - 1; 
		if(a == b) continue; 
		E[a].emplace_back(b); E[b].emplace_back(a);
		mp[make_pair(a, b)] = i + 1; 
		mp[make_pair(b, a)] = i + 1;  
	}
	for(int i = 0; i < N+1; i++) dfs(i, 100008);
	if(D[100008]){
		cout << -1 << endl; return 0; 
	}
	sort(ans.begin(), ans.end()); 
	cout << ans.size() << endl; 
	for(int i = 0; i < ans.size(); i++){
		cout << ans.at(i) << " "; 
	}
	cout << endl; 
}

Measured memory_bytes: 41596
#include<bits/stdc++.h>
#define LL long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	fastio
	LL n;
	cin>>n;
	cout<<pow(n, 3)<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    h, w, k = list(map(int, readline().split()))
    a = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
    cnt = 1
    for i in range(h):
        r_cnt = 0
        if a[i].count("#") != 0:
            for j in range(w):
                if a[i][j] == "#":
                    r_cnt += 1
                    if r_cnt != 1:
                        cnt += 1
                a[i][j] = cnt
            cnt += 1
    for i in range(h):
        if a[i].count(".") != 0:
            if i == 0:
                for ii in range(i + 1, h):
                    if a[ii].count(".") == 0:
                        for j in range(w):
                            a[i][j] = a[ii][j]
                        break
            else:
                for ii in range(i-1, -1, -1):
                    if a[ii].count(".") == 0:
                        for j in range(w):
                            a[i][j] = a[ii][j]
                        break
    for i in range(h):
        print(*a[i])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 49500
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	ll in=1000;
	for(int i=0;i<n;i++)
	cin>>a[i];
	ll f=0,st=0;
	for(int i=0;i<n-1;i++)
	{
		if(a[i]<a[i+1]&&f==0)
		{
			st=(in/a[i]);
			in-=(st*a[i]);
			f=1;
		}
		else if(a[i]>a[i+1]&&f==1)
		{
			in+=st*a[i];
			st=0;
			f=0;
		}
	}
	if(st!=0)
	in+=st*a[n-1];
	cout<<in<<endl;
	return 0;
}


Measured memory_bytes: 3632