akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)


int main() {
	int N;
	cin >> N;
	vector<string>S(N);
	rep(i, N) {
		cin >> S[i];
	}
	rep(i, N) {
		sort(S[i]);
	}
	sort(S);
	lint cnt = 1;
	lint ans = 0;
	for (int i = 1; i < N; i++) {
		if (S[i] == S[i - 1]) {
			cnt++;
		}
		else {
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	ans += cnt * (cnt - 1) / 2;
	cout << ans << endl;
}


Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] B = new int[N];
            for (int i = 0; i < N; i++)
            {
                int tmp = int.Parse(Console.ReadLine());
                A[i] = tmp;
                B[i] = tmp;
            }
            int max = A.Max();
            Array.Sort(B);
            Array.Clear(B, N -1,1);
            
            int bMax = B.Max();
            for (int j = 0; j < N; j++)
            {
                if(A[j] != max)
                {
                    Console.WriteLine(max);
                }
                else
                {
                    Console.WriteLine(bMax);
                }
            }
        }
    }
}


//long n = long.Parse(Console.ReadLine());
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine(cnt);
//Console.ReadKey();


Measured memory_bytes: 18004
//WA
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MN = 100100;
vi g[MN];
vi w;
int x;
bitset<MN> bs;
int bt[MN];
void check(int u, int p) {
	if(bs[u]) {
		bt[u]++;
		return;
	}
	for(int i=0;i<g[u].size();i++) {
		int v = g[u][i];
		if(v == p) continue;
		check(v,u);
	}
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ll ed = 0;
	bool poss = true;
	memset(bt,0,sizeof(bt));
	for(int i=0;i<n;i++) {
		if(g[i].size()&1) {
			poss = false;
			break;
		}
		if(g[i].size() > 2) {
			w.push_back(i);
			bs.set(i);
		}
		ed += g[i].size()-2;
	}
	if((ed < 4) || (!poss)) {
		cout << "No\n";return 0;
	}
	if(ed > 4) {
		cout << "Yes\n";return 0;
	}
	x = w[0];
	for(int i=0;i<g[x].size();i++) {
		check(g[x][i],x);
	}
	if(bt[x] > 0) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}


Measured memory_bytes: 7680
#include<stdio.h>

int main(){
	int a, b, c, i=0, x;
	scanf("%d %d %d", &a, &b, &c);
	for(x = a; x<=b; x++){
		if(c%x == 0){
			i++;
		}
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC112();
}

void ABC112(){
    int n,t,i,a,b,min=1000,sum=0;
    cin>>n>>t;
    for(i=0;i<n;i++){
        cin>>a>>b;
        if(a<min&&b<=t){
            min=a;
        }
        if(b>t)sum++;
    }
    if(sum==n)cout<<"TLE"<<endl;
    else cout<<min<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	long long x;
	cin>>x;

	long long result = 0;
	result += (x / 500) * 1000;
	x = x % 500;
	result += (x / 5) * 5;
	cout<<result<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define MAX 100000
#define W 0
#define G 1
#define B 2

typedef struct Node{
  int id, d;
  struct Node *next;
} node;

int m;
node data[MAX];

void insert(int a, int id, int d)
{
  node *dd, *n;

  dd = malloc(sizeof(node));
  dd->id = id;
  dd->d = d;
  dd->next = NULL;

  for (n = &data[a]; n->next != NULL; n = n->next);
  n->next = dd;
}

void dijkstra()
{
  int c[MAX], d[MAX], min, i, u, ddd;
  node *n;
  
  for (i = 0; i < m; i++){
    c[i] = W;
    d[i] = INT_MAX;
  }
  d[0] = 0;
  while (1){
    min = INT_MAX;
    for (i = 0; i < m; i++)
      if (c[i] != B && d[i] < min){
	min = d[i];
	u = i;
      }
    if (min == INT_MAX)
      break;
    c[u] = B;
    for (n = &data[u]; n != NULL; n = n->next)
      if (c[n->id] != B && d[u]+n->d < d[n->id]){
	d[n->id] = d[u] + n->d;
	c[n->id] = G;
      }
  }
  for (i = 0; i < m; i++)
    printf("%d %d\n",i,d[i]);
}

int main()
{
  int i, j, a, b, c, d;
  
  scanf("%d",&m);
  for (i = 0; i < m; i++)
    data[i].next = NULL;
  for(i = 0; i < m; i++){
    scanf("%d%d",&a,&b);
    for (j = 0; j < b; j++){
      scanf("%d%d",&c,&d);
      insert(a,c,d);
    }
  }
  dijkstra();
  
  return 0;
}



Measured memory_bytes: 1988
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 998244353
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() 
{ 
    fastio
    int n;
    cin>>n;
    vector<ll> a(n), b(n);
    for(int i = 0; i<n; ++i)
        cin>>a[i]>>b[i];

    sort(all(a)); sort(all(b));
    ll mid1 = a[n/2], mid2 = b[n/2];
    if(n%2==0) {
        mid1 += a[n/2-1];
        mid2 += b[n/2-1];
    }
    cout<<abs(mid2-mid1)+1<<endl;
} 

Measured memory_bytes: 6364
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;


int main(){
    int n, m;  cin>>n>>m;
    vi v(n);
    for(int i = 0; i < n; i++) cin>>v[i];
    sort(all(v));
    int ans = INF;
    for(int i = m-1; i < n; i++) ans = min(ans, v[i] - v[i-m+1]);
    cout<<ans;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
string s;
int len;
int ans=0;
void dfs(int d,int l,int r){
    if(d==len-1){
        ans+=l+r;
        return;
    }
    dfs(d+1,l,r*10+(s[d+1]-'0'));
    dfs(d+1,l+r,(s[d+1]-'0'));
    return;
}
signed main(){
    cin>>s;
    len=s.size();
    dfs(0,0,s[0]-'0');
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

int main(){
	ll n,tmp,x=0;
  	cin >> n;
  	tmp=n;
  	while(n!=0){
    	x+= n%10;
      	n/=10;
    }
  	if(tmp%x==0){
    	cout << "Yes"<<endl;
    }else{
    	cout << "No" << endl;
    }
}


Measured memory_bytes: 256
a, b, c, x, y = gets.chomp.split(' ').map(&:to_i)

sum = 10000000000000

# case 1: 普通に買う                                                            
tmp = a*x + b*y
sum = [sum, tmp].min

# case 2: ABピザを [x,y].max 枚買う                                             
tmp = c * 2* [x,y].max
sum = [sum, tmp].min

# case 3: ABピザを [x,y].min 枚買い, あとは単独ピザを買い足す                   
tmp = c * 2* [x,y].min
if x > y then
  tmp += a * (x-y)
elsif
  tmp += b * (y-x)
end
sum = [sum, tmp].min

puts sum


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main() {
  int N,V[20],C[20],i,ans=0;
  cin >> N;
  for(i=0;i<N;i++)cin >> V[i];
  for(i=0;i<N;i++)cin >> C[i];
  for(i=0;i<N;i++) {
    if(V[i] > C[i])ans += V[i]-C[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int n;

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

  rep(i,n){
    a[i].second=i+1;
    cin>>a[i].first;
  }
  sort(a.begin(),a.end());

  rep(i,n){
    if(a[n-1].second==i+1) cout<<a[n-2].first<<endl;
    else cout<<a[n-1].first<<endl;
  }


}

Measured memory_bytes: 4736
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	int N, M;
	cin >> N >> M;
	vi a(N), b(N);
	FOR(i, 0, N) cin >> a[i] >> b[i];
	vi c(M), d(M);
	FOR(j, 0, M) cin >> c[j] >> d[j];

	FOR(i, 0, N) {
		int ans;
		int dist = INF;
		FOR(j, 0, M) {
			int ds = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (dist > ds) {
				dist = ds;
				ans = j + 1;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){

    int a,b,d,r;
    double f;

    cin >> a >> b;

    d = a / b;
    r = a % b;
    f = (double)a / (double)b;

    cout << d << " " << r << " " << fixed << setprecision(10) << f << endl;

    
    
    
}


Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll n,k,c;
    string s;
    cin >> n >> k >> c >> s;

    vector<int> dpl,dpr;
    for (int i=0; i<n && dpl.size() < k; i++){
        if(s[i] == 'o'){
            dpl.push_back(i);
            i += c;
        }
    }
    for (int i=n; i>=0 && dpr.size() < k; i--){
        if(s[i] == 'o'){
            dpr.push_back(i);
            i -= c;
        }
    }
    reverse(dpr.begin(),dpr.end());
    for(int i=0;i<k;i++){
        if (dpl[i] == dpr[i]){
            cout << dpl[i]+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3444
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    ll N;cin>>N;
    ll M=sqrt(N)/1;
    while(M>=1){
        if(N%M==0)break;
        else M--;
    }
    ll L=N/M;
    string S=to_string(L);
    cout<<S.size()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a,b;

int main(){
	cin >> n >> a >> b;
	
	cout << ((b-a)%2?"Borys":"Alice") << endl;
	return 0;
}


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

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}

int main() {

//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    cin >> a >> b;
    if (1 > a || a > 9 || 1 > b || b > 9)
        cout << -1;
    else
        cout << a * b;

    return 0;
}




Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
        static void SolveA()
        {
            int n = ReadAndParseInt();
            long[] a = new long[n];
            for(int i=0;i<n;++i)
            {
                a[i] = ReadAndParseLong();
            }
            var alist = new List<long>(a);
            alist.Sort();

            long x0 = CalcMax(n, 0, alist);
            long x1 = CalcMax(n, 1, alist);
            long ans = Math.Max(x0, x1);

            Console.WriteLine(ans);
        }

        private static long CalcMax(int n, int minusStartIdx, List<long> alist)
        {
            var list = new List<int>(CalcCoefArr(n, minusStartIdx));
            list.Sort();

            long ans = 0;
            for (int i = 0; i < n; ++i)
            {
                ans += alist[i] * list[i];
            }
            return ans;
        }

        private static int[] CalcCoefArr(int n, int minusStartIdx)
        {
            var coefArr = new int[n];
            coefArr[0] = 1;
            coefArr[n - 1] = 1;
            for(int i=1;i<n-1;++i)
            {
                coefArr[i] = 2;
            }
            for(int i=minusStartIdx;i<n;i+=2)
            {
                coefArr[i] *= -1;
            }
            return coefArr;
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 18396
from heapq import *

def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

N, M = map( int, input().split())
V = [ i for i in range(N)]
H = [(0,0,0)]*M
for i in range(M):
    s,t,w = map( int, input().split())
    H[i] = (w,s,t)
heapify(H)
ans = 0
while H:
    w,s,t = heappop(H)
    if find(V,s) != find(V,t):
        union(V,s,t)
        ans += w
print(ans)



Measured memory_bytes: 23144
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    if (N - K >= 0)
    {
        cout << K*X + (N - K)*Y << "\n";
    }
    else
    {
        cout << N*X << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

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

int const N = 5e5 + 20 ;
int n , k , a[N] , b[N] ;

inline void build_from (int n , int a[N] , int b[N]) {
	for (int i = 0 ; i < n ; i ++) a[b[i]] = i ;
}

int mn[N] , tmp[N] ;

void solve (int l , int r) {
	if (r - l == 1) return ;

	int mid = (l + r) >> 1 ;
	solve(l , mid) , solve(mid , r) ;

	mn[mid - 1] = b[mid - 1] ;
	for (int i = mid - 2 ; i >= l ; i --) mn[i] = min(mn[i + 1] , b[i]) ;

	int p1 = l , p2 = mid , pp = l ;

	while (p1 < mid || p2 < r) {
		if (p1 == mid) tmp[pp ++] = b[p2 ++] ;
		else if (p2 == r) tmp[pp ++] = b[p1 ++] ;
		else if (mn[p1] - b[p2] >= k) tmp[pp ++] = b[p2 ++] ;
		else tmp[pp ++] = b[p1 ++] ;
	}

	for (int i = l ; i < r ; i ++) b[i] = tmp[i] ;
}

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

	cin >> n >> k ;

	for (int i = 0 ; i < n ; i ++) {
		cin >> a[i] ; 
		a[i] -- ; 
	}
	
	build_from(n , b , a) ;

	solve(0 , n) ;

	build_from(n , a , b) ;
	
	for (int i = 0 ; i < n ; i ++) cout << a[i] + 1 << '\n' ;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> graph(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--, w %= 2;
    graph[u].emplace_back(make_pair(v, w));
    graph[v].emplace_back(make_pair(u, w));
  }

  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));

  vector<int> color(N, -1);
  while (!que.empty()) {
    auto q = que.front();
    que.pop();

    int u = q.first, w = q.second;
    color[u] = w % 2;

    for (auto p : graph[u]) {
      if (color[p.first] != -1) continue;
      que.push(make_pair(p.first, w + p.second % 2));
    }
  }

  for (int i = 0; i < N; i++) {
    cout << color[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>
int main()
{
	int i, N,count=0;
scanf("%d",&N);
int a[50];
for (i=0;i<N;i=i+1){

scanf("%d",&a[i]);}
for (i=0;i<N;i=i+1){


if(a[i]==i+1)
{count=count+1;
}}


if(count>=N-2){
	printf("YES");
}
else{printf("NO");
}

}



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

int main() {
  int i, n, ac = 0, wa = 0, tle = 0, re = 0;
  char **arr;

  cin >> n;
  arr = new char*[n];
  for(i = 0; i < n; i++) {
    arr[i] = new char[4];
    cin >> arr[i];

    if(arr[i][0] == 'A') ac++;
    else if(arr[i][0] == 'W') wa++;
    else if(arr[i][0] == 'T') tle++;
    else if(arr[i][0] == 'R') re++;
  }

  cout << "AC x " << ac << '\n';
  cout << "WA x " << wa << '\n';
  cout << "TLE x " << tle << '\n';
  cout << "RE x " << re << '\n';
    
  return 0;
}


Measured memory_bytes: 7588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <numeric>

using namespace std;

int check(const vector<vector<vector<int> > >& subS, int from, int to) {
    int maxWhite = 0;
    for (int s = 0; s < subS.size(); ++s) {
        int nWhite = 0;
        for (int i = 0; i < subS[s].size(); ++i) {
            for (int j = from; j <= to; ++j) {
                nWhite += subS[s][i][j];
            }
        }
        maxWhite = max(maxWhite, nWhite);
    }
    return maxWhite;
}

int minVerticalDivision(int H, int W, int K, const vector<vector<int> >& S, bitset<15> h) {
    h = (h << 1);
    h.set(H, true);

    vector<vector<vector<int> > > subS(h.count(), vector<vector<int> >());
    int subSIdx = 0;
    for (int i = 0; i < H; ++i) {
        subS[subSIdx].push_back(S[i]);
        if (h.test(i + 1)) {
            ++subSIdx;
        }
    }

    h.reset(H);
    int ret = h.count();
    int wbegin = 0;
    for (int i = 0; i < W; ++i) {
        int k = check(subS, wbegin, i);
        if (wbegin == i && k > K) {
            return H + W;
        }
        else if (k > K) {
            ++ret;
            wbegin = i;
            if (check(subS, i, i) > K) {
                return H + W;
            }
        }
    }
    return ret;
}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int> > S(H, vector<int>(W, 0));
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < W; ++j) {
            S[i][j] = (s[j] == '1') ? 1 : 0;
        }
    }

    int ans = H + W;
    for (int i = 0; i < (1 << (H - 1)); ++i) {
        bitset<15> h(i);
        if (h.count() > ans) {
            break;
        }
        int temp = minVerticalDivision(H, W, K, S, h);
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define MOD 1000000007LL
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n,a,b;
long long calc(int xx){
	long long res=1LL;
	long long bs=2LL;
	while(xx){
		if(xx&1){
			res*=bs;
			res%=MOD;
		}
		bs*=bs;
		bs%=MOD;
		xx>>=1;
	}
	res-=1LL;
	res+=MOD;
	res%=MOD;
	return res;
}
long long inv[200100];
long long C(int x){//C(n,x)
	long long res=1LL;
	for(int i=1;i<=x;i++){
		//C(n,i)
		res*=inv[i];
		res%=MOD;
		res*=(long long)(n-i+1);
		res%=MOD;
	}
	return res;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>a>>b;
	inv[1]=1LL;
	for(int i=2;i<=200000;i++)//递推逆元 
		inv[i]=(MOD-((MOD/i)*inv[MOD%i])%MOD);
	long long ret=calc(n);
	long long tmp;
	tmp=C(a);
	ret-=tmp;
	ret%=MOD;
	ret+=MOD;
	ret%=MOD;
	tmp=C(b);
	ret-=tmp;
	ret%=MOD;
	ret+=MOD;
	ret%=MOD;
	cout<<ret<<endl;
	return 0;
}


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

using namespace std;

//???????????????????????????ver
void BabbleSort(int N, vector<int> array){

	int v,count=0;

	for (int i = 0; i < N-1; i++){
	
		for (int j = i+1; j < N; j++){
			if (array[i] > array[j]){
				v = array[i];
				array[i] = array[j];
				array[j] = v;
				count++;
			}
		}
	
	}

	//?????????????????¨?????????????????°for(i)?????????????????°??????
	for (int k = 0; k < N; k++){
		cout << array[k];
		if (k != N - 1)cout << " ";
	}cout << endl;

	cout << count << endl;



}

//??????????????????????????????ver
void BabbleSort_a(int N, vector<int> array){

	int v, count = 0;

	for (int i = N-1; i > 0; i--){

		for (int j = 0; j < i; j++){
			if (array[i] < array[j]){
				v = array[i];
				array[i] = array[j];
				array[j] = v;
				count++;
			}
		}

	}

	for (int k = 0; k < N; k++){
		cout << array[k];
		if (k != N - 1)cout << " ";
	}cout << endl;

	cout << count << endl;



}

//???????????°ver?????????????????????
void bubbleSort(int N, vector<int> array){
	int v;
	int x = 0;
	int flag = 1;
	while (flag){
		flag = 0;
		for (int j = N - 1; j>0; j--){
			if (array[j] < array[j - 1]){
				v = array[j];
				array[j] = array[j - 1];
				array[j - 1] = v;
				flag = 1;
				x++;
			}
		}
	}

	for (int k = 0; k < N; k++){
		cout << array[k];
		if (k != N - 1)cout << " ";
	}cout << endl;

	cout << x << endl;


	
}



int main(){

	int N,Num;
	cin >> N;

	vector<int> array(N, 0);

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


	bubbleSort(N,array);


	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }

    int max_l = k - (a[n-1] - a[0]);
    for(int i=0;i<n-1;++i) max_l = max(max_l, a[i+1] - a[i]);

    cout << k - max_l << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int main(){
	while(true){
		int n,x; cin >> n >> x;
		if(n==0 && x==0) break;
		int sum=0;
		for(int i=1;i<=n;++i){
			for(int j=i+1;j<=n;++j){
				for(int k=j+1;k<=n;++k){
					if(i+j+k==x) ++sum;
				}
			}
		}
		cout << sum << '\n';
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define n_max 100000


vector< int > tree[n_max];
void DFS(int tmp,int pre[],int cnt[]){
    cnt[0]+=1;
    for(auto itr = tree[tmp].begin() ; itr != tree[tmp].end() ; itr ++){
        if(pre [ *itr ] == -1){
            pre[*itr] = tmp;
            DFS(*itr, pre,cnt);
        }
    }
}

int main(){
    int n;
    cin >> n;
    int a,b;
    REP(i,n-1){
        scanf("%d%d",&a,&b);
        tree[a-1].push_back(b-1);
        tree[b-1].push_back(a-1);
    }
    int pre[n_max];
    REP(i,n) pre[i]=-1;
    pre[0]=0;
    int black[1];
    DFS(0,pre,black);



    int length=0,tmp=n-1;
    while(1){
        length+=1;
        tmp=pre[tmp];
        if(tmp==0) break;
    }
    int cut;
    if(length%2==0){
        cut = length /2 -1;
    }
    else cut = int(length /2);


    length=0;
    tmp=n-1;
    while(1){
        if(length==cut) break;
        length+=1;
        tmp=pre[tmp];
    }

    itrfor(itr,tree[tmp]){
        if(*itr == pre[tmp]){
            tree[tmp].erase(itr);
            break;
        }
    }

    itrfor(itr,tree[pre[tmp]]){
        if(*itr == tmp){
            tree[pre[tmp]].erase(itr);
            break;
        }
    }

    black[0]=0;
    REP(i,n) pre[i]=-1;
    pre[0]=0;
    DFS(0,pre,black);

    if(black[0] * 2 > n) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 10752
n = gets.to_i

def division_times(k)
  t = 0
  while (k % 2).zero?
    k /= 2
    t += 1
  end
  t
end

max_times = 0
fav_num = 1

(2..n).each do |k|
  if division_times(k) > max_times
    max_times = division_times(k)
    fav_num = k
  end
end

puts fav_num

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<ll>& v)
{
  std::for_each(v.begin(), v.end(), [](ll x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main ()
{
    ll N;cin>>N;
    vector<ll> A(N);
    vector<ll> B(N);
    ll flag = 0;
    REP(i,N){
        cin>>A[i];
        B[i] = abs(A[i]);
        if(A[i]<0) flag++;
    }
    sort(ALL(B));
    ll s = accumulate(B.begin(),B.end(),0LL);
    if(flag%2==0){
        cout<<s<<endl;
        return 0;
    }else{
        cout<<s-2*B[0]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;


int main()
{
    int i,j;
    int N;
    set<string> st;

    scanf("%d", &N);
    for( i=1; i<=N; i++)
    {
        string s;
        cin>>s;
        st.insert(s);
    }

    printf("%d\n", st.size());

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 19244
import sys
import math
import itertools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, k = na()
s = ns()
c = 0
for key, val in itertools.groupby(s):
    c += len(list(val)) - 1
ans = min(c + 2*k, n-1)
print(ans)

Measured memory_bytes: 3956
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n, a, b, maxIdx, ans int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		if maxIdx < a {
			maxIdx = a
			ans = a + b
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6440
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll K;
  cin >> K;
  int ind=0;
  while(K > 0){
    if(ind == (int) s.size() - 1){
      int tmp = (s[ind] -'a' + K%26)%26 + 'a';
      //      cout << tmp << endl;
      s[ind] = tmp;
      K=0;
    }
    else if(s[ind] == 'a'){
      ind++;
    }

    else if (K >= 'z' -  s[ind] + 1){
      K -= ('z' -  s[ind] + 1);
      s[ind]='a';
      ind++;      
    }
    else{
      ind++;
    }
  }
  rep(i,(int)s.size()){
    cout << s[i];

  }

  cout << ""<< endl;
  return 0;
    

}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;

int n,d,ans=0;
double x,y;

signed main()
{
	cin>>n>>d;
	for (int i=1;i<=n;i++)
	{
		cin>>x>>y;
		
		double len=sqrt(x*x+y*y);
		if (len<=d)  ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<math.h>
#include <algorithm>
using namespace std;
int c[500];
int main(){
	for(int i=0;i<500;i++){c[i]=i*(i+1)/2;}
	int n;cin>>n;
	int j=0;
	bool hoge=false;
	for(;j<500;j++){
		if(c[j]==n){hoge=true;break;}
	}
	if(hoge==false){cout<<"No"<<endl;}
	else{
		cout<<"Yes"<<endl;
		cout<<j+1<<endl;
		int d[500];
		d[0]=0;
		d[1]=j;
		for(int i=2;i<500;i++){d[i]=d[i-1]+(j-i+1);}
		for(int k=1;k<=j+1;k++){
			cout<<j<<" ";
			for(int h=1;h<=k;h++){
				if(h!=k){cout<<d[h-1]+(k-h)<<" ";}
				else{
					for(int p=d[h-1]+1;p<=d[h];p++){
					cout<<p;
						if(p!=d[h]){cout<<" ";}
					}
				}
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1408
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import Data.Array
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main :: IO()
main= do
  [n, k, q] <- getIntList
  ns <- accumArray (+) (k - q) (1, n) . (flip zip [1,1..]) <$> replicateM q getInt
  forM_ [1..n] $ \n ->
    if ns!n > 0
      then putStrLn "Yes"
      else putStrLn "No"

-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine


Measured memory_bytes: 28412
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        // O(n^2) time | O(n) space
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        StringBuilder middle = new StringBuilder(in.next());
        StringBuilder head = new StringBuilder();
        StringBuilder tail = new StringBuilder();
        boolean reverse = false;

        int tests = in.intNext();
        for (int t = 0; t < tests; t++) {
            if (in.intNext() == 1) {
                reverse = !reverse;
            } else if (in.intNext() == 1) {
                if (!reverse) head.append(in.charNext());
                else tail.append(in.charNext());
            } else {
                if (!reverse) tail.append(in.charNext());
                else head.append(in.charNext());
            }
        }
        StringBuilder result = new StringBuilder();
        if (!reverse) {
            head.reverse();
            result.append(head);
            result.append(middle).append(tail);
        } else {
            tail.reverse();
            middle.reverse();
            result.append(tail).append(middle).append(head);
        }
        out.println(result);
        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 46952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  string s;
  int k;
  cin>>s>>k;
  int n=s.size();

  rep(i,n){
    if(s[i]=='a') continue;
    if('z'-s[i]+1<=k) {
      k-='z'-s[i]+1;
      s[i]='a';
    }
  }

  s[n-1]+=k%26;

  cout << s << endl;
}

Measured memory_bytes: 512
import sys
from operator import itemgetter
from collections import defaultdict

inputs =  list(map(int, sys.stdin.readline().split()))
N = inputs[0]

dic = defaultdict(list)
for i in range(N):
    inputs = list(sys.stdin.readline().split())
    dic[inputs[0]].append({"value":int(inputs[1]), "key":i+1})


sort = sorted(dic.items(), key=itemgetter(0))

for s in sort:
    scores_sorted = sorted(s[1], key=lambda x: x['value'], reverse=True)
    for score in scores_sorted:
        print(score.pop("key"))

Measured memory_bytes: 3352
#include<stdio.h>
int ans;
int d[202][202];
void solve(int g[], int n[], int gn, int nn)
{
	if (nn == 0)
	{
		int scor = 0;
		int i;
		for (i = 0; i < gn - 1; i++)
			scor += d[g[i]][g[i + 1]];
		if (ans > scor)
			ans = scor;
	}
	else
	{
		int a[11], b[11];
		int i, j, k;
		for (i = 0; i < nn; i++)
		{
			k = 0;
			for (j = 0; j < nn; j++)
			{
				if (i != j)
				{
					a[k] = n[j];
					k++;
				}
			}
			for (j = 0; j < gn; j++)
				b[j] = g[j];
			b[gn] = n[i];
			solve(b, a, gn + 1, nn - 1);
		}
	}
	return;
}
int main()
{
	int n, m, R;
	scanf("%d %d %d", &n, &m, &R);
	int i, j, k;
	int r[10];
	for (i = 0; i < R; i++)
	{
		scanf("%d", &r[i]);
		r[i]--;
	}
	int a[20004], b[20004], c[20004];
	for (i = 0; i < m; i++)
	{
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		a[i]--;
		b[i]--;
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			d[i][j] = 1e9;
	for (i = 0; i < m; i++)
		d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (d[i][j] > d[i][k] + d[k][j])
					d[i][j] = d[i][k] + d[k][j];
	ans = 1e9;
	int p[10] = {};
	solve(p, r, 0, R);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  string ans="";
  for (size_t i = 0; i < S.length()/2; i++) {
    ans += "hi";
  }
  cout << (S == ans ? "Yes" : "No") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


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

using namespace std;

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

    vector<int>A;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin>>a;
        A.push_back(a);
    }

    vector<int>B;
    for (int i = 0; i < N; i++)
    {
        int b;
        cin>>b;
        B.push_back(b);
    }

    vector<int>C;
    for (int i = 0; i < N-1; i++)
    {
        int c;
        cin>>c;
        C.push_back(c);
    }

    int ans=0;
    int prev=0;
    for(const auto&a:A)
    {
        ans+=B[a-1];
        if(a-prev==1)
        {
            ans+=C[a-2];
        }
        prev=a;
    }
    
    cout << ans << endl;
    return 0;   
}

Measured memory_bytes: 3616
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN, datC, datK) = readLine.split(" ").map(_.toInt)
    val datA_ = for(i <- 1 to datN) yield (readLine.split(" ").map(_.toInt).head)
    val datA = datA_.sorted.toArray

    def countBus(result: Int, timelimit: Int, people: Int, cur: Int): Int = {
      if(datA.length == cur) result
      else {
        if((datA(cur) > timelimit) || (people >= datC)) countBus(result + 1, datA(cur) + datK, 1, cur + 1)
        else countBus(result, timelimit, people + 1, cur + 1)
      }
    }
    val ans = countBus(1, datA(0) + datK, 1, 1)
    println(ans)
  }
}


Measured memory_bytes: 39752
from collections import deque
S=input()
Q=int(input())
ans=deque(S)
cnt=0
for _ in range(Q):
    i=(input().split())
    if(int(i[0]) == 1):
        cnt= (cnt+1) % 2
    elif((cnt== 0 and i[1]=='1') or (cnt == 1 and i[1]=='2')):
        ans.appendleft(i[2])
    else:
        ans.append(i[2])
ans=''.join(ans)
print(ans[::-1]) if(cnt % 2 == 1) else print(ans)


Measured memory_bytes: 8820
PROGRAM-ID.                      ABC_043_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 s1.
        03 s11 OCCURS 10.
            05 s PIC X(1).

    01 ans1.
        03 ans11 OCCURS 10.
            05 ans PIC X(1).

    01 i       PIC 9(2).

    01 len     PIC 9(2).
    01 now     PIC 9(2).

PROCEDURE                        DIVISION.
    ACCEPT s1.

    COMPUTE len = FUNCTION STORED-CHAR-LENGTH(s1).

    MOVE ZERO TO now.

    PERFORM VARYING i FROM 1 BY 1 UNTIL len < i
        IF s(i) = 'B' THEN
            IF now NOT = ZERO THEN
                MOVE SPACE TO ans(now)
                SUBTRACT 1 FROM now
            END-IF
        ELSE
            ADD 1 TO now
            MOVE s(i) TO ans(now)
        END-IF
    END-PERFORM.

    DISPLAY ans1(1:FUNCTION STORED-CHAR-LENGTH(ans1)).
    STOP RUN.


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin>>a[i];
  sort(a.begin(), a.end());
  int sum = 0;
  for(int i=0; i<k; i++) {
    sum += a[i];
  }
  cout<<sum<<endl;
}

  

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

vector<int> G[100005];
int parent[100005];
vector<int> childs[100005];
int jump[20][100005];
int depth[100005];

void dfs0(int u, int p = 0) {
  parent[u] = p;
  if (p == 0)
    depth[u] = 0;
  else
    depth[u] = depth[p] + 1;
  for (int h : G[u])
    if (h != p) {
      childs[u].push_back(h);
      dfs0(h, u);
    }
}

int up(int u, int d) {
  for (int i = 19; i >= 0; i--)
    if (d & (1 << i))
      u = jump[i][u];
  return u;
}

int down(int u, int ref, int d) { return up(ref, depth[ref] - depth[u] - d); }

int lca(int u, int v) {
  if (depth[u] > depth[v])
    swap(u, v);
  v = up(v, depth[v] - depth[u]);
  if (u == v)
    return u;
  for (int i = 19; i >= 0; i--)
    if (jump[i][u] != jump[i][v])
      u = jump[i][u], v = jump[i][v];
  return parent[u];
}

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

  int n, a, b;
  cin >> n >> b >> a;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  dfs0(a);

  for (int i = 1; i <= n; i++)
    jump[0][i] = parent[i];
  for (int j = 1; j < 20; j++)
    for (int i = 1; i <= n; i++)
      jump[j][i] = jump[j - 1][jump[j - 1][i]];

  // for (int i = 1; i <= n; i++) {
  //   printf("%d Depth %d\n", i, depth[i]);
  // }

  int ans = max(0, depth[b] - depth[a] - 1);

  for (int i = 1; i <= n; i++)
    if (i != a && i != b) {
      int an = lca(i, b);

      int mva = 0, mvb = 0;
      int pa = a, pb = b;

      // printf("%d Ancestor %d\n", i, an);

      if (depth[b] - depth[an] < depth[an] - depth[a]) {
        // goto an first
        mva += depth[b] - depth[an];
        mvb += depth[b] - depth[an];
        pb = an;
        pa = down(pa, pb, depth[b] - depth[an]);
        // goto i then
        mvb += depth[i] - depth[an];
        mva += depth[i] - depth[an];
        pb = i;
        pa = down(pa, pb, depth[i] - depth[an]);
        mva += depth[pb] - depth[pa] - 1;
        ans = max(ans, mva);
      } else {
        continue;
      }
    }

  cout << ans << endl;
}

Measured memory_bytes: 24704
N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]

A  =[[0] * N for _ in range(N)] #A[i][j] = (i + 1) -> (j+1)なる列車の本数
for train in trains:
    li, ri = train
    A[li - 1][ri - 1] += 1

dp = [[0] * N for __ in range(N)]
for i in range(N - 1, -1, -1):
    for j in range(i, N):
        if i == j:
            dp[i][j] = A[i][j]
        else:
            dp[i][j] = dp[i][j - 1] + dp[i + 1][j] + A[i][j] - dp[i + 1][j - 1]
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][ qi - 1])



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

int main(void) {
	string A, B, ans;

	cin >> A >> B;
	if (A.length() > B.length())
		ans = "GREATER";
	else if (A.length() < B.length())
		ans = "LESS";
	else {
		if(A > B)
			ans = "GREATER";
		else if (A < B)
			ans = "LESS";
		else
			ans = "EQUAL";
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256