akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



signed main() {
	fio();
	int n, k;
	cin >> n >> k;
	vl sei, fu;
	rep (i, n) {
		ll x;
		cin >> x;
		if (x >= 0) sei.push_back(x);
		else fu.push_back(-x);
	}

	sei.push_back(0);
	fu.push_back(0);

	sort(all(sei));
	sort(all(fu));
	DEBUG_VEC(sei);
	DEBUG_VEC(fu);
	ll ans = INF;
	rep (i, min((int)sei.size(), k + 1)) {
		if (k - i >= 0 and k - i < fu.size()) {
			//DEBUG(pii(i, k - i));
			chmin(ans, 2 * sei[i] + fu[k - i]);
			chmin(ans, sei[i] + 2 * fu[k - i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll N,M,L,O,P,Q,R;
string S;

int main(){
    cin>>N;
    vector<int>p(N);
    int ans=0;
    for(int i=0;i<N;i++)cin>>p[i];
    for(int i=1;i<N-1;i++){
        vector<int> tmp(3);
        tmp[0]=p[i-1];
        tmp[1]=p[i];
        tmp[2]=p[i+1];
        sort(tmp.begin(),tmp.end());
        if(tmp[1]==p[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

  vector<int> data;
  for (int i = 0; i < n; ++i)
  {
    int card;
    cin >> card;
    data.push_back(card);
  }

  sort(data.begin(), data.end(), greater<int>());

  int point = 0;
  int sign = 1;
  for (int i = 0; i < data.size(); ++i)
  {
    point += (sign * data[i]);
    sign *= -1;
  }
  cout << point << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    const int MXX = 100 + 5;

    int a[MXX];
    int main ()
    {
        int n;
        cin>>n;
        int mx = -200; ll ans = 1e9;
        for(int i = 0; i<n; i++)cin>>a[i], mx = max(a[i], mx);
        for(int i = -100; i<=100; i++)
        {
            ll make = i, cost = 0;
            for(int j = 0; j<n; j++)
            {
                if(a[j] == make)continue;
                ll x = a[j] - make;
                x*=x;
                cost+=(x);
            }
            ans = min(cost, ans);
        }
        if(ans == 1e9) ans = 0;
        cout<<ans<<endl;
        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int sum(int n);

int main()
{
	int n;
	
	cin >> n;
	
	vector<int> x(n), y(n);
	double ans = 0;

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];

		for (int j = 0; j < i; j++) {
			ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}
	
	if (n == 2) {
		printf("%.10f\n", ans);
	}
	else {
		printf("%.10f\n", ans / (n*0.5));
	}

	return 0;
}

int sum(int n)
{
	return (int)(n * (n + 1) * 0.5);
}


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

int	main()
{
	int	N;
	cin >> N;
	if (N % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<int>	d_vec(N);
	for (int i = 0; i < N; ++i)
		cin >> d_vec.at(i);
	sort(d_vec.begin(), d_vec.end());
	int	left_median = d_vec.at((N-1)/2);
	int	right_median = d_vec.at(N/2);
	cout << right_median - left_median << endl;
	return 0;
}



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

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    cout << min( B/A, C ) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class A
{
	public static void Main()
	{		
		char c = GetString()[0];
		switch(c)
		{
			case 'a':
			case 'i':
			case 'u':
			case 'e':
			case 'o':
				Console.WriteLine("vowel");
				return;

			default:
				Console.WriteLine("consonant");
				return;
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n; cin >> n;
  int f[101][11];
  int p[101][11];
  for (int i = 1; i < n+1; i++) {
    for (int j = 1; j < 11; j++) {
        cin >> f[i][j];
    }
  }
  for (int i = 1; i < n+1; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  int max_cost = -INT_MAX;
  for (unsigned int i = 1; i < (1<<10); i++) {
    int counter[101] = {};
    int j = 1;
    for (unsigned int flg = 1; flg < (1<<11); flg<<=1, j++) {
      if (i & flg) {
        for (int k = 1; k < n+1; k++) {
          if (f[k][j]>0) counter[k]++;
        }
      }
    }
    int cost = 0;
    for (int k = 1; k < n+1; k++) {
      cost += p[k][counter[k]];
    }
    max_cost = max(max_cost, cost);
  }
  cout << max_cost << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,h[20],i,cs,top;
int main(void){
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&h[i]);
    }
    
    for(i = 0;i < n;i++){
    if(i==0){
        cs+=1;
        top = h[i];
    }else if(h[i] - top >= 0){
        top = h[i];
        cs += 1;
    }
    }
    printf("%d",cs);
    return 0;
}


Measured memory_bytes: 128
def pow2(i):
    ret = 1
    while i!=1:
        i >>= 1
        ret <<= 1
    return ret

m = int(input())

points = []
max2 = -1
flag = True
bias = -1
for i in range(m):
    point = list(map(int,input().split()))
    dis = abs(point[0])+abs(point[1])
    if (dis > max2):
        max2 = dis
    if (bias!=-1 and dis%2 != bias%2):
        flag =False
    if (dis%2 == 0):
        point[0] -= 1 
    points.append(tuple(point))
    bias = dis%2
if flag == False:
    print("-1")
    exit(0)        

bias = max2%2
max2 = pow2(max2)
diss = []
dirctions = [""]*m
while max2>0:
    for i in range(m):
        point = points[i]
        
        if (point[1]>point[0] and point[1]>(-point[0])):
            dirctions[i] = "U"+dirctions[i]
            points[i] = (point[0],point[1]-max2)
        elif(point[1]>point[0] and point[1]<(-point[0])):
            dirctions[i] = "L"+dirctions[i]
            points[i] = (point[0]+max2,point[1])
        elif(point[1]<point[0] and point[1]>(-point[0])):
            dirctions[i] = "R"+dirctions[i]
            points[i] = (point[0]-max2,point[1])
        else:
            dirctions[i] = "D"+dirctions[i] 
            points[i] = (point[0],point[1]+max2)
    diss = [max2] + diss
    max2 >>= 1

if (bias == 0):
    diss = [1] + diss
    for i in range(m):
        dirctions[i] = "R"+dirctions[i]
print(len(diss))
for d in diss:
    print(str(d),end=" ")
print("")
for d in dirctions:
    print(d)


Measured memory_bytes: 3316
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n];
		int b[] = new int[m];
		for(int i=0;i<n;i++) a[i] = sc.nextInt();
		for(int i=0;i<m;i++) b[i] = sc.nextInt();
		int max = 0;
		for(int i=0;i<m;i++) {
			int p = i;
			for(int j=0;j<n;j++) {
				if(a[j] == b[p]) p++;
				if(p == m) break;
			}
			max = max(max, p-i);
		}
		System.out.println(max);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a==1) a+=13;
  if(b==1) b+=13;
  if(a>b){
    cout << "Alice";
  }else if(b>a){
    cout << "Bob";
  }else{
    cout << "Draw";
  }
}

Measured memory_bytes: 256
import java.util.*;
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 = 0;
		String [] str1 = new String [a];
        String [] str2 = new String [b];
        for(int i=0;i<a;i++){str1[i] = sc.next();                             
                            }
        for(int i=0;i<b;i++){str2[i] = sc.next();                           
                            }
		String s = "No";
        for(int i=0;i<a-b+1;i++){ 
        for(int j=0;j<a-b+1;j++){c=0;                                                
        for(int k=0;k<b;k++){
          if(str1[i+k].substring(j,j+b).equals(str2[k])){c++;} 
          if(c==b){s = "Yes";break;}                       
        }       
                                }                                 
        }      
		System.out.println(s);
	}
}


Measured memory_bytes: 24020
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<string, int> s_map;
    REP(i, n) {
        string s;
        cin >> s;
        s_map[s]++;
    }
    int m;
    cin >> m;
    REP(i, m)  {
        string t;
        cin >> t;
        s_map[t]--;
    }

    int ans = 0;
    for(auto p : s_map) ans = max(ans, p.second);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,res=0;
  cin>>n;
  vector<int> s(n);
  for(auto &i:s)cin>>i;
  sort(s.begin(),s.end());
  for(int l=0;l<n-2;++l)for(int r=l+1;r<n-1;++r){
    int k = lower_bound(s.begin()+r+1,s.end(),s[l]+s[r])-(s.begin()+r+1);
    res+=k;
  }
  cout<<res;
}

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

 int main()
 {
     int n;
     cin >> n;
     long long int a[n],result;
     for(int i=0;i<n;i++){
        cin >> a[i];
     }
     long long int maxi=a[0],mini =a[0];
     for(int i=1;i<n;i++){
        if(a[i]>=maxi){
            maxi=a[i];
        }
        if(a[i]<=mini){
            mini=a[i];
        }
     }
     result=maxi-mini;
     cout << result << endl;
     return 0;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w, srow,scol,erow,ecol;
	cin >> h >> w >> srow >> scol>> erow >> ecol;
//	int srow,scol,erow,ecol;
//	cin >> srow >> scol;
//	cin >> erow >> ecol;
	--srow,--scol,--erow,--ecol;
	string grid[h];
	for(int i = 0; i < h;++i){
		cin >> grid[i];
	}
//	bool ok = false;
	deque<pair<int,int> > dq;
	int dist[h][w];
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w;++j){
			dist[i][j] = 1e7;
		}
	}
	dist[srow][scol] = 0;
	dq.push_back({srow,scol});
	while(!dq.empty()){
		pair<int,int> cur_node = dq.front();
		dq.pop_front();
//		int row = cur_node.first;
//		int col = cur_node.second;
//		if(row == erow && col == ecol){
//			ok = true;
//			break;
//		}
		for(int dx = -2;dx <= 2;++dx){
			for(int dy = -2;dy <= 2;++dy){
				int nrow = cur_node.first + dx;
				int ncol = cur_node.second + dy;
//				if(nrow == row && ncol == col)
//					continue;
				if(nrow < 0 || ncol < 0 || nrow >= h || ncol >= w ||(!dx && !dy) || grid[nrow][ncol] == '#')
					continue;
				int w = 1;
//				if(grid[nrow][ncol] == '#')
//					continue;
//				if((abs(nrow-row) == 1 && abs(ncol-col) == 0) || (abs(ncol-col) == 1 && abs(nrow-row) == 0))
//					w = 0;
                if((abs(dx) == 1 && dy == 0) || (abs(dy) == 1 && dx== 0))
                    w = 0;
				if(dist[nrow][ncol] > dist[cur_node.first][cur_node.second] + w){
					dist[nrow][ncol] = dist[cur_node.first][cur_node.second] + w;
					(w?dq.push_back({nrow,ncol}):dq.push_front({nrow,ncol}));
//						dq.push_front({nrow,ncol});
//						dq.push_back({nrow,ncol});
				}
			}
		}
	}
//	if(!ok)
//		dist[erow][ecol] = -1;
//	cout << dist[erow][ecol] << "\n";
    cout<<(dist[erow][ecol] == 1e7?-1: dist[erow][ecol]);
    return 0;
}

Measured memory_bytes: 8720
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct UnionFind{
  vector<int> par,rank;
  UnionFind(int N){
    par.resize(N);
    rank.resize(N);
    for(int i=0;i<N;i++){
      par[i]=i;
      rank[i]=1;
    }
  }
  int find(int x){
    if(par[x]==x)
      return x;
    else{
      int y=find(par[x]);
      par[x]=y;
      return y;
    }
  }
  void unite(int x,int y){
    int x2=find(x),y2=find(y);
    if(x2==y2)
      return;
    if(rank[x2]>=rank[y2])
      par[y2]=x2,rank[x2]=max(rank[x2],rank[y2]+1);
    else
      par[x2]=y2;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
};
signed main(){
  int N,K,L;
  cin>>N>>K>>L;
  UnionFind A(N),B(N);
  while(K--){
    int a,b;
    cin>>a>>b;
    A.unite(a-1,b-1);
  }
  while(L--){
    int a,b;
    cin>>a>>b;
    B.unite(a-1,b-1);
  }
  map<pair<int,int>,int> C;
  for(int i=0;i<N;i++)
    C[{A.find(i),B.find(i)}]++;
  for(int i=0;i<N;i++){
    cout<<C[{A.find(i),B.find(i)}];
    if(i==N)cout<<endl;
    else cout<<' ';
  }
}

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

using namespace std;

const long long R = 1e9 + 7; string s; int n, p; long long dp[ 2 ][ 4 ];

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr ), cin >> s, n = s.size(), dp[ 0 ][ 3 ] = 1;

    for( int i = n, j = n - 1, q = 1; i > 0; i = j--, p = q, q = 1 - p )
        for( int k = 4, l = 3; k > 0; k = l-- )
        {
            auto &x = dp[ q ][ l ];  x = dp[ p ][ l ];

            if ( s[ j ] == '?' )
                x *= 3, x %= R;

            if( k < 4 and ( s[ j ] == '?' or ( s[ j ] - 'A' ) == l ) )
                x += dp[ p ][ k ], x %= R;
        }

    cout << dp[ p ][ 0 ];
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    ll K;
    cin >> K;
    set<char> st(S.begin(), S.end());
    if (st.size() == 1) {
        cout << S.size() * K / 2 << '\n';
        return 0;
    }
    ll cnt1 = 0;
    char cur = S[0];
    for (int i = 0; i < S.size() - 1; i++) {
        if (cur == S[i+1]) {
            cnt1++;
            i++;
        }
        cur = S[i+1];
    }
    ll ans = K * cnt1;
    //cout << ans << '\n';
    if (*S.begin() == *S.rbegin()) {
        int a = 1, b = 1;
        for (int i = 0; S[i] == S[i+1]; i++, a++) {;}
        for (int i = S.size() - 1; S[i] == S[i-1]; i--, b++) {;}
        //cout << a << b << '\n';
        ans += -(K - 1) * (a/2 + b/2) + (K - 1) * ((a + b) / 2);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    rep(i,0,2){
        if(s[i]!=s[i+1]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
/*  UntilDeathDoesUsApart
    DO   NOT   GIVE   UP!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define pi               (ld)3.14159265359
#define inc(a)           a.begin(), a.end()
#define dec(a)           a.rbegin(), a.rend()
#define Unique(n)        (n).erase(unique(in(n)), (n).end())
#define what_is(x)       cerr << #x << " is " << x << '\n';
#define to(i, a, n)      for(int i=a; i<n; i++)
#define fr(i, a, n)      for(int i=a; i>=n; i--)
#define read(arr, l, r)  for(int i=l; i<r; cin >> arr[i++])
#define prnt(arr, l, r)  for(int i=l; i<r; cout << arr[i++] << " \n"[i==r])

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    ld a, b, h, m, ang, d;
    cin >> a >> b >> h >> m;
    ang = cos((h*30.0 - 5.5*m)/180*pi);
    d = sqrt(a*a + b*b - 2*a*b*ang);
    cout << fixed << setprecision(9) << d;

    return 0;
}


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

using namespace std;

int main(){
    long long int N,count=0,sum=0;
    bool zero=false;
    cin >> N;
    vector<long long int> A(N),B(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        B[i] = abs(A[i]);
        sum += B[i];
        if(A[i]<0){
            count++;
        }else if(A[i]==0){
            zero = true;
        }
    }

    sort(B.begin(),B.end());

    if(count%2==0 || zero){
        cout << sum << endl;
    }else{
        cout << sum-B[0]*2 << endl;
    }
}

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

int main() {
  int N; std::cin >> N;
  std::set<int> s;
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    if(s.count(A) > 0) {
      std::cout << "NO" << std::endl;
      return 0;
    }
    s.insert(A);
  }
  std::cout << "YES" << std::endl;
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int main() {
	int m; cin >> m;
	long long sum = 0, ans = -1;
	for (int i = 0; i < m; ++i) {
		long long d, c; cin >> d >> c;
		sum += d * c;
		ans += c;
	}
	long long tmp = sum;
	while (tmp > 9) {
		ans += tmp / 10;
		tmp = tmp / 10 + tmp % 10;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    low = 1 / (4*m)
    count = 0
    x = sum(a)
    for i in range(n):
        if a[i]>=x*low:
            count += 1
    if count>=m:
        print("Yes")
    else:
        print("No")
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
# DFS(深さ優先探索)
def create_links(N, K):
    links = [[] for _ in range(N)]
    for _ in range(K):
        p, q = map(int, input().split())
        links[p - 1].append(q - 1)
        links[q - 1].append(p - 1)
    return links


def create_groups(N, links):
    groups = list(range(N))
    for i in range(N):
        if groups[i] != i:
            continue
        q = [i]
        while q:
            j = q.pop()
            for k in links[j]:
                if groups[k] != i:
                    groups[k] = i
                    q.append(k)
    return groups


N, K, L = map(int, input().split())

road_links = create_links(N, K)
rail_links = create_links(N, L)
road_groups = create_groups(N, road_links)
rail_groups = create_groups(N, rail_links)

d = {}
for i in range(N):
    t = (road_groups[i], rail_groups[i])
    if t in d:
        d[t] += 1
    else:
        d[t] = 1

print(*[d[(road_groups[i], rail_groups[i])] for i in range(N)])


Measured memory_bytes: 89224
//Stable sort

#include<stdio.h>
#define N 100
#define TRUE 1
#define FALSE 0

typedef struct
{
  char suit;
  int num;
}card;

int main()
{
  int i,j,n;
  card arr1[N],arr2[N], swit;
  
  //input data
  scanf("%d",&n);
  for(i = 0; i < n; i++)  scanf(" %c%d",&arr1[i].suit, &arr1[i].num);
    
  //initialize a array2 for selection sort
  for(i = 0; i < n; i++) arr2[i] = arr1[i];

  //bubble
  for(i = 0; i < n-1; i++)
    {
      for(j = n - 1; j >= i+1; j--)
	{
	  swit = arr1[j];
	  if(arr1[j].num < arr1[j-1].num)
	    {
	      arr1[j] = arr1[j-1];
	      arr1[j-1] = swit;
	    }
	}
    }

  //select
  for(i = 0; i < n-1; i++)
    {
      int min = i;
      for(j = i; j < n; j++)
	{
	  if(arr2[j].num < arr2[min].num) min = j;
	}
      card swit = arr2[i];
      arr2[i] = arr2[min];
      arr2[min] = swit;
    }

  //check stable
  int judge = 1;
  for(i = 0; i < n; i++)
    {
      if(arr1[i].suit != arr2[i].suit) judge = 0;
    }

  //output data
  for(i = 0; i < n; i++)
    {
      if(i > 0) printf(" ");
      printf("%c%d",arr1[i].suit,arr1[i].num);
    }
  printf("\n");
  printf("Stable\n");

  for(i = 0; i < n; i++)
    {
      if(i > 0) printf(" ");
      printf("%c%d",arr2[i].suit,arr2[i].num);
    }
  printf("\n");

  if(judge) printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;
}



Measured memory_bytes: 2088
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, M;
  cin >> N >> M;
  struct ST {
    ll problem;
    bool ac;
  };
  vector<ll> pena(N);
  vector<bool> fix(N);

  for (ll i = 0; i < M; i++) {
    ll p;
    string s;
    cin >> p >> s;
    p--;
    if (s == "WA" && !fix[p]) {
      pena[p]++;
    } else if (s == "AC" && !fix[p]) {
      fix[p] = true;
    }
  }
  ll ans = 0;
  ll ans_pena = 0;
  for (ll i = 0; i < N; i++) {
    if (fix[i]) {
      ans++;
      ans_pena += pena[i];
    }
  }

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


Measured memory_bytes: 1024
fun main(arg: Array<String>) {
    val (H, W, N) = listOfInt()
    val M = mutableMapOf<Pair<Int, Int>, Int>()
    repeat(N) {
        val (a, b) = listOfInt(-1)
        for (h in -1 .. 1) for (w in -1 .. 1) {
            val key = a + h to b + w
            if ((key.first in 1 until H - 1) && (key.second in 1 until W - 1))
                M.set(a + h to b + w, M.getOrElse(a + h to b + w, { 0 }) + 1)
        }
    }
    val ans = LongArray(10)
    M.forEach { m -> ans[m.value] = ans[m.value] + 1 }
    ans[0] = (1L * (H - 2) * (W - 2)) - ans.sum()
    ans.forEach { println(it) }
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }



Measured memory_bytes: 205076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;

using namespace std;

int main() {
    string S;
    cin >> S;
    int b = S.size();
    int max = (1 << (b - 1));
    ll sum = 0;
    for(unsigned int i = 0; i < max; i++){
        ll tmp = 0;
        ll tmp1 = 0;
        for(int j = 0; j < b - 1; j++){
            tmp1 += S[j] - '0';
            if(i & 1 << j){
                tmp += tmp1;
                tmp1 = 0;
            }else{
                tmp1 *= 10;
            }
        }
        tmp += tmp1;
        tmp += S[b - 1] - '0';
        sum += tmp;
    }
    cout << sum << endl;

}

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

using namespace std;

typedef long long ll;
int main()
{
    
    ll n;
    cin>>n;
    ll arr[n+2];
    for(int i=1;i<=n+1;i++) cin>>arr[i];
    ll cnt=0;
    for(int i=1;i<=n;i++){
        ll a; cin>>a;
        if(a<arr[i]) cnt+=a;
        else { cnt+=arr[i];  a=a-arr[i]; arr[i]=0;
            if(a>=arr[i+1]){ cnt+=arr[i+1]; arr[i+1]=0; }
            else { cnt+=a; arr[i+1]-=a; }
        }
        // cout<<arr[i]<<" "<<arr[i+1]<<endl;
        // cout<<cnt<<endl;
    }
    cout<<cnt<<endl;
    
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.io.*;
import java.util.*;

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

        int max = Math.max(a,c);
        int min = Math.min(b,d);
        int count = min -max;
        ans = Math.max(0, count);
        /* if(a<c && b<d && b<= c||c<a && b<d && b<=a ||a<c && d<b && d <= c ||c<a && d<b && d<=a){
            ans = 0;
        }
            else if(a<c && b<d && c<d){
                ans = b-c;
            }else if(c<a && b<d && a<d){
                ans = b-a;
            }else if(a<c && d<b && c<b){
                ans = d-c;
            }else if(c<a && d<b && a<b){
                ans = d-a;
            }
        */    
            System.out.println(ans);
        
        
    }

}

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

using namespace std;

int n;
char a[101];

int main()
{
    int cou = 0;
    scanf("%d",&n);
    scanf("%s",a);
    for(int i = 0;i < n;i++)
        if(a[i] == 'R')
            cou++;
    if(cou > n - cou)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import math

def main():
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A3 = list(map(int, input().split()))
    n = int(input())
    B = [int(input()) for _ in range(n)]

    bingo = [[0]*3]+[[0]*3]+[[0]*3]

    A = [A1, A2, A3]
    row_sum1 = 0
    row_sum2 = 0
    row_sum3 = 0
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if B[i]==A[j][k]:
                    bingo[j][k] = 1
    for i in range(len(bingo)):
        if sum(bingo[i])==3:
            print('Yes')
            return
        row_sum1 += bingo[i][0]
        row_sum2 += bingo[i][1]
        row_sum3 += bingo[i][2]

    if bingo[0][0] == bingo[1][1] == bingo[2][2] == 1 or bingo[0][2] == bingo[1][1] == bingo[2][0] == 1:
        print('Yes')
        return
    if row_sum1==3 or row_sum2==3 or row_sum3==3:
        print('Yes')
        return
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38448
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            Array.Sort(a);
            BigInteger ans = 1;
            for (int i = 0; i < n; i++)
            {
                if (ans <= (long)Math.Pow(10, 18))
                    ans *= a[i];
                else
                    break;
            }
            WriteLine(ans > (long)Math.Pow(10, 18) ? -1 : ans);














          
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 40328
#include<iostream>
#include<vector>
using namespace std;
int a,b,k[1000];
long sum[1001];
vector<long>v;
int main(){
	cin>>a>>b;
	for(int i=0;i<a;i++)cin>>k[i];
	for(int i=0;i<a;i++)sum[i+1]=sum[i]+k[i];
	for(int i=0;i<a;i++){
		for(int j=i+1;j<=a;j++)v.push_back(sum[j]-sum[i]);
	}
	long ans=0;
	for(int i=50;i>=0;--i){
		vector<long>mon;
		for(int j=0;j<v.size();j++){
			if(v[j]>>i&1)mon.push_back(v[j]);
		}
		if(mon.size()>=b){
			v=mon;
			ans|=(long long)1<<i;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6512
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()

  d = {}
  for _ in range(n):
    s = "".join(sorted(ns()))
    if s in d:
      d[s] += 1
    else:
      d[s] = 1

  ans = 0
  for k, v in d.items():
    ans += (v * (v - 1)) // 2
  print(ans)

main()

Measured memory_bytes: 17848
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    int n, W;
    cin >> n >> W;
    vector<ll> min_weight(100001, INT_MAX);
    min_weight[0]=  0;
    for(int i = 0; i < n; i++) {
        int weights, value;
        cin >> weights >> value;

        for(int j = 100001 - value; j >= 0; j--)
            min_weight[j + value] = min(min_weight[j + value], min_weight[j] + weights);
    }

    int ans = 0;
    for(int i = 0; i < 100001; i++)
        if(min_weight[i] <= W)
			ans = max(ans, i);

    cout << ans;

}


Measured memory_bytes: 4048
#include<stdio.h>
#include<stdlib.h>

int main(){
  int m,n,i,j,k,l,**array;
  scanf("%d",&n);
  array = malloc(sizeof(int *)*n);
  for(i=0;i<n;i++)array[i]=malloc(sizeof(int)*n);
  for(i=0;i<n;i++)for(j=0;j<n;j++)array[i][j]=0;
  
  k=n;
  while(k--){
    scanf("%d %d",&i,&l);
    while(l--){
      scanf("%d",&m);
      array[i-1][m-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j<n-1)printf("%d ",array[i][j]);
      else printf("%d\n",array[i][j]);
    }
  }
  for(i=0;i<n;i++)free(array[i]);
  free(array);
  return 0;
}
  



Measured memory_bytes: 2056
#include <iostream>
#include <vector>

int main()
{
	int X;
	int Y;
	std::string answer = "No";

	std::cin >> X >> Y;

	if (X * 2 == Y)
	{
		answer = "Yes";
	}
	else if (X * 4 == Y)
	{
		answer = "Yes";
	}
	else
	{
		for (int turu = 1; turu < X; turu++)
		{
			for (int kame = 1; kame <= X - turu; kame++)
			{
				if ((turu * 2 + kame * 4 == Y) && (turu+kame == X))
				{
					answer = "Yes";
					break;
				}
			}
		}
	}

	std::cout << answer;

	return 0;
}


Measured memory_bytes: 3628
k, x = map(int, input().split())
ans_list = [x]
original_x = x

for _ in range(k - 1):
    x = x - 1
    ans_list.append(x)

for _ in range(k - 1):
    if _ == 0:
        x = original_x
    x = x + 1
    ans_list.append(x)

ans_list.sort()
print(' '.join(map(str, ans_list)))

Measured memory_bytes: 9192
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dh[]={1,-1,0,0};
int dw[]={0,0,1,-1};
//mleしなければぜんぶllでかく。
int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      int n;
      cin>>n;
      string a,b,c;
      cin>>a>>b>>c;
      ll ans=0;
      rep0(i,n){
            if(a[i]==b[i]&&b[i]==c[i]){
                  ans+=0;
            }
            else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
                  ans+=1;
            }
            else{
                  ans+=2;
            }
      }
      cout<<ans<<endl;

      return 0;
}

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

#include <vector>

template < typename data_type >
class fenwick_tree {

  std::size_t size_;
  std::vector< data_type > data_;

public:
  fenwick_tree(size_t size) : size_(size), data_(size + 1) {}

  data_type get_sum(int k) {
    data_type sum = 0;
    for (; k; k -= k & -k) sum += data_[k];
    return sum;
  }

  void add(int k, data_type x) {
    for (; k <= size_; k += k & -k) data_[k] += x;
  }
};


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

  fenwick_tree< int > fnc(n);
  
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com) {
      cout << fnc.get_sum(y) - fnc.get_sum(x - 1) << endl;
    } else {
      fnc.add(x, y);
    }
  }
}




Measured memory_bytes: 3124
n = int(input())
number = [0] * n
s = [0] * n
p = [0] * n

for i in range(n):
  number[i] = i+1
  s[i], p[i] = input().split()
  p[i] = int(p[i])
  
for i in range(n):
  for j in range(1, n-i):
    if s[j-1] > s[j]:
      s[j-1], s[j] = s[j], s[j-1]
      p[j-1], p[j] = p[j], p[j-1]
      number[j-1], number[j] = number[j], number[j-1]
    elif (s[j-1] == s[j]) and (p[j-1] < p[j]):
      s[j-1], s[j] = s[j], s[j-1]
      p[j-1], p[j] = p[j], p[j-1]
      number[j-1], number[j] = number[j], number[j-1]
      
for i in range(n):
  print(number[i])

Measured memory_bytes: 39792
#include <iostream>

using namespace std;

int main(){
    long long N, M, a, b;

    cin >> N >> M;

    if (N==1){
        a = 1;
    }else{
        a = N - 2;
    }

    if (M==1){
        b = 1;
    }else{
        b = M - 2;
    }

    cout << a*b << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int a,b,c;cin >> a >> b >> c;
  bool f = false;
  for(int i = b; i <= c; ++i) {
    if(i % a == 0) f = true;
  }
  if(f) cout << "OK" << "\n";
  else cout << "NG" << "\n";
  return 0;
}


Measured memory_bytes: 3676
#include <vector>
#include <iostream>
#include <stdio.h>

using namespace std;


struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; ++i) {
			par[i] = i;
		}
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {

		int rx = root(x);
		int ry = root(y);
		if (rx == ry) {
			return;
		}
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n, q, x, y;
	cin >> n >> q;
	UnionFind S(n);
	bool com;
	for (int i = 0; i < q; ++i) {
		cin >> com >> x >> y;
		if (com) {
			if (S.same(x, y)) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
		else {
			S.unite(x, y);
		}
	}
	return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
    int n;cin>>n;
    vector<ll> a(n);
    vector<pLL> t(n);
    repsg(i,0,n){
        cin>>a[i];
        t[i] = pLL(a[i],i);
    }
    map<ll,ll> mp;
    rep(i,n){
        mp[a[i]]=i;
    }
    set<ll> st;
    sort(all(t));
    
    st.insert(-1);
    st.insert(n);
    
    ll ans = 0;
    
    repsg(i,0,n){
        
        ll num = t[i].second;
        auto it = st.lower_bound(num);
        
        ll r = (*it);
        it--;
        ll l = (*it);

        ans += (t[i].first * (r-num)*(num-l));
        
        st.insert(num);
    }
    
    cout<<ans<<endl;
    
    
    return 0;
}




Measured memory_bytes: 26752
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine((nk[0] - 1 + nk[1] - 1 - 1) / (nk[1] - 1));
    }
}


Measured memory_bytes: 18016
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)%2)
typedef long long ll;
typedef long double ld;
const ll oo=2*1000*1000*1000;
const int _cnt=1000*1000;
const int _p=1000*1000*1000+7;
int o(int x) { return x%_p; }
int gcd(int a,int b) { return b?gcd(b,a%b):a; }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
using namespace std;

void file_put(){
	freopen("filename.in","r",stdin);
	freopen("filename.out","w",stdout);
}

int a,b,x; 

int main(){
	//file_put();
	
	scanf("%d%d%d",&x,&a,&b);
	if (b-a<=0) return 0*printf("delicious\n");
	if (b-a>x) return 0*printf("dangerous\n");
	printf("safe\n");
  
	return 0;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 100005;

int deg[N], c[N], done[N], d[N];
vector<int> con[N];

int main(){
	int n; sd(n);
	for(int i = 1; i < n; i++){
		int a, b; 
		sd(a); sd(b);
		con[a].push_back(b); con[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	set<pair<int, int> > st;
	for(int i = 1; i <= n; i++){
		sd(c[i]);
	}
	sort(c + 1, c + n + 1);

	for(int i = 1; i <= n; i++){
		st.insert({deg[i], i});
	}
	int iter = 0;
	ll ans = 0;
	while(!st.empty()){
		pii it = *st.begin();
		int node = it.S;
		d[node] = c[++iter];
		if(iter != n) ans += c[iter];
		for(auto x : con[node]) if(!done[x]){
			st.erase({deg[x], x});
			deg[x]--;
			st.insert({deg[x], x});
		}
		done[node] = 1;
		st.erase(it);
	}

	printf("%lld\n", ans);
	for(int i = 1; i <= n; i++) printf("%d ", d[i]);
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline lint ty()
	{
		lint a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

inline lint gcd(lint a,lint b)
{
	while(b)a%=b,swap(a,b);
	return a;
}

int main()
{
	lint n=ty(),x=ty();
	printf("%lld\n",3ll*(n-gcd(n,x)));

	return 0;
}


Measured memory_bytes: 256
#coding:utf-8



def main():
    n = int(input())
    P = list(map(int,input().split()))
    c = 0
    for i in range(1,n-1):
        if (P[i-1] <= P[i] and P[i] < P[i+1]) or\
        (P[i-1] > P[i] and P[i] >= P[i+1]):
            c += 1
    print(c)
if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
n=int(input())
w=[input() for _ in range(n)]
setw = set(w)
if(len(setw)!=len(w)):
    print("No")
    exit()

endw=w[0][-1]
for ww in w[1:]:
    if(endw!=ww[0]):
        print("No")
        exit()
    endw=ww[-1]

print("Yes")
    


Measured memory_bytes: 3060
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
x=0
y=0
R=0
z=0
s=0
while (x<X or y<Y) and z<X+Y:
  if (max(p[0],q[0],r[0])==p[0] or (y==Y and r[0]<p[0])) and x<X:
    s+=p[0]
    x+=1
    if x<A:
      p[0]=p[x]
    else:
      p[0]=0
    z+=1
  elif (max(p[0],q[0],r[0])==q[0] or (x==X and r[0]<q[0])) and y<Y:
    s+=q[0]
    y+=1
    if y<B:
      q[0]=q[y]
    else:
      q[0]=0
    z+=1
  else:
    s+=r[0]
    R+=1
    if R<C:
      r[0]=r[R]
    else:
      r[0]=0
    z+=1
print(s)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string a, b;
  cin >> a >> b;
  a += b;
  int n = stoi(a);
  rep(i,1,1000) {
    if (i*i == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
module mod_selection_sort
  implicit none
  integer, private, parameter :: intkind = 4
contains
  logical function less(a, b) result(res)
    integer(intkind), intent(in) :: a, b
    res = a <= b
  end
  subroutine swap(a, b)
    integer(intkind), intent(inout) :: a, b
    a = xor(a, b)
    b = xor(a, b)
    a = xor(a, b)
  end
  subroutine selection_sort(a)
    integer(intkind), intent(inout) :: a(:)
    integer :: n, i, j, m
    n = size(a)
    do i = 1, n - 1
      m = i
      do j = i + 1, n
        if (.not.less(a(m), a(j))) m = j
      end do
      if (i /= m) call swap(a(i), a(m))
    end do
  end
end module mod_selection_sort
program brave_chain
  use mod_selection_sort
  implicit none
  integer, parameter :: inf = 1e9
  integer :: n, a(6000) = 0, dp(2000, 2000) = -inf, m = 0, b(3) = 0, v, i, j
  integer, dimension(2000) :: dp0 = 0, mv = -inf, mv0 = 0
  read(*,*) n
  read(*,*) a(1:3 * n)
  call update(a(1), a(2), 0)
  do i = 3, 3 * n - 2, 3
    if (a(i) == a(i + 1) .and. a(i) == a(i + 2)) then
      m = m + 1
      cycle
    end if
    call selection_sort(a(i:i + 2))
    if (a(i + 1) == a(i + 2)) call swap(a(i), a(i + 2))
    do j = 1, n
      dp0(j) = dp(min(a(i), j), max(a(i), j))
    end do
    mv0(1:n) = mv(1:n)
    v = max(0, maxval(mv(1:n)))
    do j = 1, 3
      b(j) = dp(a(i + j - 1), a(i + j - 1))
    end do
    if (a(i) == a(i + 1)) then
      do j = 1, n
        call update(a(i + 2), j, dp0(j) + 1)
      end do
    end if
    call update(a(i + 1), a(i + 2), b(1) + 1)
    call update(a(i), a(i + 2), b(2) + 1)
    call update(a(i), a(i + 1), b(3) + 1)
    call update(a(i + 1), a(i + 2), v)
    call update(a(i), a(i + 2), v)
    call update(a(i), a(i + 1), v)
    do j = 1, n
      call update(a(i), j, mv0(j))
      call update(a(i + 1), j, mv0(j))
      call update(a(i + 2), j, mv0(j))
    end do
  end do
  i = a(3 * n)
  write(*,'(i0)') max(dp(i, i) + 1, maxval(mv(1:n))) + m
contains
  subroutine update(a, b, z)
    integer, intent(in) :: a, b, z
    integer :: x, y
    if (a > b) then
      x = b
      y = a
    else
      x = a
      y = b
    end if
    if (dp(x, y) >= z) return
    dp(x, y) = z
    mv(x) = max(mv(x), z)
    mv(y) = max(mv(y), z)
  end
end program brave_chain

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

using namespace std;

int n, m;
vector<int> edges[10];

int dfs(int curr, int mask) {
	if(mask == (1<<n)-1) return 1;
	int ret = 0;
	for(int out: edges[curr]) {
		if(!(mask&(1<<out))) {
			ret += dfs(out, mask | (1 << out));
		}
	}
	return ret;
}

int main() {
	scanf("%d%d", &n, &m);
	while(m--) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	printf("%d\n", dfs(0, 1));
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
template <class T> using vec = std::vector<T>;
template <class T> using vvec = std::vector<std::vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

void rec(int i, int p, int x, const vvec<int>& od, const vec<int>& c, vec<int>& result)
{
    result[i] += x;
    for (auto& o : od[i])
    {
        if (o != p) rec(o, i, x + c[o], od, c, result);
    }
    return;
}

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

    int K, X; cin >> K >> X;
    for (int i = -K + 1; i < K; ++i)
    {
        cout << X + i << " ";
    }

    return 0;
}


Measured memory_bytes: 256