akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        int A = 0;
        int B = 0;
        int AB = 0;
        long count = 0;

        for(int i=0; i<n; i++) {
            var s = input.ReadLine();
            for(int j=1; j<s.Length; j++) {
                if(s[j-1] == 'A' && s[j] == 'B') {
                    count++;
                }
            }
            var isA = s.Last() == 'A';
            var isB = s.First() == 'B';
            if(isA && isB) AB++;
            else if(isA) A++;
            else if(isB) B++;
        }

        if(AB > 0) {
            if(A > 0){
                A--;
                count++;
            }
            count += AB-1;
            if(B > 0) {
                B--;
                count++;
            }
        }

        count += Math.Min(A,B);

        return count;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 11220
S=list(input())

K=(len(S)+1)//2

if len(S)%2==0:
  mark=S[len(S)//2]
  if mark!=S[len(S)//2-1]:
    print(K)
    exit()
  count=1
  while(0<len(S)-K-count):
    if mark!=S[len(S)//2-1-count] or mark!=S[len(S)//2+count]:
      print(K+count)
      exit()
    count+=1
  print(K+count)
else:
  mark=S[len(S)//2]
  count=0
  while(0<len(S)-K-count):
    if mark!=S[len(S)//2-1-count] or mark!=S[len(S)//2+1+count]:
      print(K+count)
      exit()
    count+=1
  print(K+count)

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

int main(){
  int sum, N;
  cin >> N;
  int t = N;
  while (t>0){
    sum += t % 10;
    t /= 10;
  }
  if (N%sum==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[10000], f[10000];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld", &a[i]);
	sort(a, a+n);
	int mx = a[n-1], ans = 1;
	
	if(mx%2 == 0){
		if(a[0] != mx/2)ans = 0;
		f[0] = 1;
		for(int i = mx/2+1;i <= mx;i++){
			int p = lower_bound(a, a+n, i)-a;
			if(p+1 >= n or a[p] != i or a[p+1] != i){ans = 0;break;}
			f[p] = f[p+1] = 1;
		}
		rep(i,n){
			if(f[i] == 0 and a[i] <= mx/2)ans = 0;
		}
	}else{
		for(int i = (mx+1)/2;i <= mx;i++){
			int p = lower_bound(a, a+n, i)-a;
			if(p+1 >= n or a[p] != i or a[p+1] != i){ans = 0;break;}
			f[p] = f[p+1] = 1;
		}
		rep(i,n){
			if(f[i] == 0 and a[i] <= (mx+1)/2)ans = 0;
		}
	}
	
	printf("%s\n", ans ? "Possible" : "Impossible");
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"    "<<"HERE"<<en

int main(){
  int l,a,b,c,d;
  cin>>l>>a>>b>>c>>d;
  
  int m,j;
  if(a%c) m=a/c+1;
  else m=a/c;
  if(b%d) j=b/d+1;
  else j=b/d;
  int l1=max(m,j);
  
  cout<<l-l1<<en
}





































































































































































































































































































































































































































































































































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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

const double pi = acos(-1.0);
int main(){
    double r;
    cin >> r;
    printf("%.6f %.6f\n", pi*r*r, 2*pi*r);
    return 0;
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

bool bfs(int pos);

vector<P> graph[SIZE];
bool visit[SIZE];
int dist[SIZE];

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

    int n, m;
    cin >> n >> m;
    while(m--) {
        int l, r, d;
        cin >> l >> r >> d;
        graph[l].pb(MP(r, d));
        graph[r].pb(MP(l, -d));

    }

    for(int i = 1; i <= n; ++i) {
        dist[i] = INF;

    }
    bool f = true;
    for(int i = 1; i <= n; ++i) {
        if(!visit[i]) f = f & bfs(i);

    }
    if(f) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

bool bfs(int pos) {
    queue<P> q;
    q.push(MP(pos, 0));

    visit[pos] = true;
    dist[pos] = 0;
    while(!q.empty()) {
        P p = q.front();
        q.pop();

        for(int i = 0; i < graph[p.F].size(); ++i) {
            if(visit[graph[p.F][i].F]) {
                if(p.S + graph[p.F][i].S != dist[graph[p.F][i].F]) {
                    return false;

                }
            } else {
                visit[graph[p.F][i].F] = true;
                dist[graph[p.F][i].F] = p.S + graph[p.F][i].S;
                q.push(MP(graph[p.F][i].F, dist[graph[p.F][i].F]));

            }

        }
    }

    return true;
}



Measured memory_bytes: 12032
H,W=[int(x) for x in input().split()]
M=[['.' for _ in range(W+2)] for _ in range(H+2)]
for h in range(1,H+1):
  M[h][1:W+1]=list(input())

for h in range(1,H+1):
  for w in range(1,W+1):
    if M[h][w]=='#': continue
    c=0
    for x in range(-1,2):
      for y in range(-1,2):
        if x==0 and y==0:
          continue
        elif M[h+x][w+y]=='#':
          c+=1
    M[h][w]=str(c)
  else:
    print(''.join(M[h][1:W+1]))

Measured memory_bytes: 3188
n, l = map(int, input().split())
 
taste = []
mini = 10**9
suf = 0
for i in range(1,n+1):
    if abs(l+i-1) < mini:
        mini = abs(l+i-1)
        suf = i
    taste.append(l+i-1)
 
taste.pop(suf-1)
print(sum(taste))

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	ll h;
	cin >> h;
	ll i=1, count = 1;
	h = h/2;
	while(h!=0){
		h /= 2;
		//cout << h << " " << count << endl;
		//count += 2;
		//if(h==1) count += i;
		count += pow(2, i);
		//cout << h << " " << count << endl;
		i++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	if(n % k == 0) cout << "0" << endl;
	else cout << "1" << endl;
	rtn 0;
}

Measured memory_bytes: 256
s=list(input())
if s[0]=='A' and s[1].islower():
    s=s[2:len(s)]
    if s[:len(s)-1].count('C')==1:
        s.remove('C')
        if ''.join(s).islower() :
            print("AC")
            exit()    
print("WA")

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

int main(void){
  int dice[7];
  for(int i = 1;i < 7;++i){
    scanf("%d", dice + i);
  }

  int q;
  scanf("%d", &q);
  for(int i = 0;i < q;++i){
    int top, front, right;
    scanf("%d %d", &top, &front);
    for(int i = 1;i < 7;++i){
      if(dice[i] == top){
        top = i;
      }
      if(dice[i] == front){
        front = i;
      }
    }
    if(top == 1){
      switch(front){
        case 2:
          right = 3;
          break;
        case 3:
          right = 5;
          break;
        case 4:
          right = 2;
          break;
        case 5:
          right = 4;
          break;
      }
    }else if(top == 2){
      switch(front){
        case 1:
          right = 4;
          break;
        case 3:
          right = 1;
          break;
        case 4:
          right = 6;
          break;
        case 6:
          right = 3;
          break;
      }
    }else if(top == 3){
      switch(front){
        case 1:
          right = 2;
          break;
        case 2:
          right = 6;
          break;
        case 5:
          right = 1;
          break;
        case 6:
          right = 5;
          break;
      }
    }else if(top == 4){
      switch(front){
        case 1:
          right = 5;
          break;
        case 2:
          right = 1;
          break;
        case 5:
          right = 6;
          break;
        case 6:
          right = 2;
          break;
      }
    }else if(top == 5){
      switch(front){
        case 1:
          right = 3;
          break;
        case 3:
          right = 6;
          break;
        case 4:
          right = 1;
          break;
        case 6:
          right = 4;
          break;
      }
    }else if(top == 6){
      switch(front){
        case 2:
          right = 4;
          break;
        case 3:
          right = 2;
          break;
        case 4:
          right = 5;
          break;
        case 5:
          right = 3;
          break;
      }
    }

    printf("%d\n", dice[right]);
  }

  return 0;
}



Measured memory_bytes: 3200
#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
/*UnionFind*/
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,M;
	scan(N>>M);
	UnionFind uf(N);
	rep(i,M){
		int A,B;
		scan(A>>B);
		A--;
		B--;
		uf.unite(A,B);
	}
	int num=0;
	rep(i,N){
		if(uf.root(i)==i) num++;
	}
	prin(num-1);
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll res = 1;
    vector<ll> now(3, 0);
    REP(i, N){
    	ll cnt = 0;
    	REP(j, 3){
    		if(A[i] == now[j]) cnt++;
    	}
    	res *= cnt;
    	res %= mod;
    	REP(j, 3){
    		if(A[i] == now[j]){
    			now[j]++;
    			break;
    		}
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	vector<int> h(n);
	for (int i=0; i<n; i++)
		cin>>h[i];
	int ret=0;
	for (int i=0; i<n; i++) {
		if (h[i]>=k)
			ret++;
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";
#ifndef ONLINE_JUDGE
#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);
#else
#define freopen ios_base::sync_with_stdio(0);cin.tie(0); //Alperen_T
#endif

int main(){
	freopen

	int a, b, c, d, i = 0;
	cin >> a >> b >> c >> d;
	while(true){
		if(i % 2 == 0){
			c -= b;
		}
		else{
			a -= d;
		}
		i++;
		if(a <= 0){
			cout << "No";
			return 0;
		}
		if(c <= 0){
			cout << "Yes";
			return 0;
		}
	}
} 

Measured memory_bytes: 3648
n, a, b = map(int, input().split())
out = 0

if (b-a)%2 == 0:
  out = (b-a)//2
else:
  aa = a - 1
  bb = n - b
  if aa < bb:
    a = 1
    b = b - aa - 1
    out += (aa + 1)
    out += (b-a)//2
  else:
    b = n
    a = a + bb + 1
    out += (bb + 1)
    out += (b-a)//2
print(out)
    
    

Measured memory_bytes: 3060
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 500011; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	Query queries[q];
	for(int i=0;i<q;i++)
	{
		int l1,r1;
		cin>>l1>>r1;
		l1--;r1--;
		queries[i].l = l1; 
	queries[i].r = r1; 
	queries[i].idx = i; 
	}
	 
	
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 17424
#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 ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;
const int INF =1000000;


int main(){
int x; cin>>x;
bool flag=1;
if(x<100)flag=0;
else {
  int n=x%100; int m=x/100;
  int sum=0; int min_pay=0;
  while(sum<n){
     sum+=5;
     min_pay++;
  }
  if(min_pay>m)flag=0;
}
cout<<(flag ? 1:0)<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 100000;
const int INF = 1<<30;

class Edge{
    public:
        int t, w;
        Edge(){}
        Edge(int t, int w): t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];

bool visited[MAX];
int cnt;

void bfs(int s){
    for(int i=0; i<n; i++) d[i] = INF;
    queue<int> Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        for(int i=0; i<G[u].size(); i++){
            Edge e = G[u][i];
            if(d[e.t] == INF){
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve(){
    bfs(0);
    int maxv = 0;
    int tgt = 0;
    for(int i=0; i<n; i++){
        
        if(maxv < d[i]){
            maxv = d[i];
            tgt = i;
        }
    }

    bfs(tgt);
    maxv = 0;
    for(int i=0; i<n; i++){
        
        maxv = max(maxv, d[i]);
    }

    cout << maxv << endl;
}

int main(){
    int s, t, w;
    cin >> n;

    for(int i=0; i<n-1; i++){
        cin >> s >> t >> w;

        G[s].push_back(Edge(t,w));
        G[t].push_back(Edge(s,w));
    }

    solve();
}


Measured memory_bytes: 9900
p = 1000000007

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print(0)
    exit()

a = (2 * Y - X) // 3
b = (2 * X - Y) // 3

if a < 0 or b < 0:
    print(0)
    exit()

n = a + b
fac = [0] * (n + 1)
fac[0] = 1
for i in range(n):
    fac[i + 1] = fac[i] * (i + 1) % p


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], p - 2, p) * pow(fac[k], p - 2, p) % p


print(mcomb(n, a))
#他者の解答を参考にした

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    ll eight = 1;
    ll nine = 1;
    ll ten = 1;
    rep(i, N) {
        (eight *= 8) %= MOD;
        (nine *= 9) %= MOD;
        (ten *= 10) %= MOD;
    }
    ll temp = (ten + eight) % MOD;
    ll temp2 = (nine + nine) % MOD;
    temp = (temp - temp2) % MOD;
    if(temp < 0) temp += MOD;
    cout << temp << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			

void solve()
{     int mx=0,i,n,k;double ans=0.00000;
 cin >> n>>k;int A[n+5],dp[n+5];
 for(i=1;i<=n;i++)
 {
     cin>>A[i];
     dp[i]=dp[i-1]+A[i];
 }
 for(i=k;i<=n;i++)
 {
     mx=max(mx,dp[i]-dp[i-k]);
     //ans = ans + (mx+1)/2.000000000000;
 }
 ans=(mx+k)/2.0000000000;
 cout << fixed << setprecision(10)<<ans;

}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
const int mod = 1000000007;

ll modpow(ll x, ll y, ll p = mod)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int fact[402020], revfact[402020];
int ncr(int n, int r)
{
    return ((fact[n]*revfact[r])%mod)*revfact[n-r]%mod;
}

int nhr(int n, int r)
{
    return ncr(n+r-1, r)%mod;
}

int32_t main()
{
    fact[0] = 1; revfact[0] = 1;
    for (int i = 1; i<=400000; i++)
    {
        fact[i] = fact[i-1]*i;
        fact[i] %= mod;
    }
    for (int i = 1; i<=400000; i++)
        revfact[i] = modpow(fact[i],mod-2);
    int n, k;
    cin >> n >> k;
    if (k >= n-1)
    {
        cout << nhr(n, n) << '\n';
        return 0;
    }
    int free = min(n, k);
    if (free <= n)
    {
        int ans = 0;
        for (int i = n; i>=max(n-free, 1ll); i--)
        {
            int use_room = i;
            //printf("Useroom %lld\n",use_room);
            int u = nhr(i, n-i);
            //printf("Personchooseroom %lld\n",u);
            int v = ncr(n, i);
            //printf("Chooseroom %lld\n",v);
            u *= v;
            u %= mod;
            ans += u%mod;
            ans %= mod;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
	int n,d;
	cin>>n>>d;
	int cnt=0;
	for(int i=0; i<n; i++)
	{
		double x,y;
		cin>>x>>y;
		double tmp=sqrt(x*x+y*y);
		if(tmp<=double(d)) cnt++;
	}
	
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3788
N = int(input())
A = [int(a) for a in input().split()]

x = A[N - 1]
i = -1
for j in range(N):
    if A[j] <= x:
        i += 1
        A[i], A[j] = A[j], A[i]

for j, a in enumerate(A):
    if j == 0:
        print(a, end='')
    elif j == i:
        print(' [{}]'.format(a), end='')
    else:
        print(' {}'.format(a), end='')
print()


Measured memory_bytes: 16364
from sys import stdin

input = stdin.readline
import math

def solve():
    n = int(input())
    a = list(map(int, input().split()))

    cur = 0
    for i in a:
        cur = math.gcd(i, cur)
    if cur > 1:
        print('not coprime')
        return
    m = max(a)
    prime = [True] * (m+1)
    c = {}
    for i in a:
        c[i] = c.get(i,0) + 1
    for i in range(2,m+1):
        if prime[i]:
            cnt = 0
            for j in range(i,m+1,i):
                prime[j] = False
                cnt += c.get(j,0)
                if cnt > 1:
                    print('setwise coprime')
                    return
    print('pairwise coprime')
if __name__ == '__main__':
    solve()


Measured memory_bytes: 257196
import sys
read = sys.stdin.buffer.read
 
N, K, *h = map(int, read().split())
# print(N, K, h)
 
def chmin(l, i, v):
  if l[i] > v:
    l[i] = v
    return True
  return False
 
def chmax(l, i, v):
  if l[i] < v:
    l[i] = v
    return True
  return False
 
# コスト無限大で初期化
INF = float("inf")
dp = [ INF ] * N
dp[0] = 0
 
for i in range(1, N):
  # i番目の梯子までの最小移動コストは、
  # 「i-1番目までの移動コスト」+「i-1番目からi番目への移動コスト」
  # もしくは、
  # 「i-2番目までの移動コスト」+「i-2番目からi番目への移動コスト」
  # ...
  # もしくは、
  # 「i-K番目までの移動コスト」+「i-K番目からi番目への移動コスト」
  # のうち、最も小さいものが、最小移動コストになる
  
  # jをi-Kからi-1まで変化させながら、最小の組み合わせを探す
  # ただし、jが負の値にならないよう注意
  for j in range(max(0, i-K), i):
    chmin(dp, i, dp[j] + abs(h[i] - h[j]))
  # print(dp)
 
print(dp[N-1])

Measured memory_bytes: 56508
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n=int(input())
    s = [tuple(map(int, input().split())) for i in range(n)]
    a = sorted(i[0] for i in s)
    b = sorted(i[1] for i in s)
    if len(s) % 2 == 1:
        lft = a[n//2]
        rgt = b[n//2]
        print(rgt - lft + 1)
        return
    lft = a[n//2] + a[n//2-1]
    rgt = b[n//2] + b[n//2-1]
    print(rgt - lft + 1)

main()

Measured memory_bytes: 126516
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline ll getint(){
  ll _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline ll add( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x + _y;
  if( _ >= _mod ) _ -= _mod;
  return _;
}
inline ll sub( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x - _y;
  if( _ < 0 ) _ += _mod;
  return _;
}
inline ll mul( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x * _y;
  if( _ >= _mod ) _ %= _mod;
  return _;
}
ll mypow( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 1ll;
  ll _tmp = mypow( _a , _x / 2 , _mod );
  _tmp = mul( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = mul( _tmp , _a , _mod );
  return _tmp;
}
ll mymul( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 0ll;
  ll _tmp = mymul( _a , _x / 2 , _mod );
  _tmp = add( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = add( _tmp , _a , _mod );
  return _tmp;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
void build(){

}
LL n , s , ans = -1;
void check( LL bs ){
  LL ts = 0 , tn = n;
  while( tn ){
    ts += tn % bs;
    tn /= bs;
  }
  if( ts == s ){
    if( ans == -1 || bs < ans )
      ans = bs;
  }
}
void init(){
  n = getint();
  s = getint();
}
void solve(){
  if( n <= 1000000 ){
    for( LL i = 2 ; i <= n + 1 ; i ++ )
      check( i );
  }else{
    for( LL i = 2 ; i * i <= n ; i ++ )
      check( i );
    check( n + 1 );
    for( LL i = 1 ; i * i <= n ; i ++ ){
      LL res = s - i;
      if( i > s ) break;
      if( ( n - res ) % i ) continue;
      LL bs = ( n - res ) / i;
      if( i >= bs || res >= bs ) continue;
      check( bs );
    }
  }
  printf( "%lld\n" , ans );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,x1,x2;
	scanf("%d %d",&x1,&x2);
	if(x1==x2){
		a=0;
	}
	else if(x1>x2){
		a=x1-x2;
	}
	else if(x1<x2){
		a=x2-x1;
	}
	printf("%d\n",a);
	return 0;
}


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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=2e5+10;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

i32 N,K,A[MAXN],B[MAXN];

int main(){
    N=read();
    K=read();
    f(i,1,I,N) A[i]=read();

    while(K--){
        bool isFinished=1;
        f(i,1,I,N) isFinished&=(A[i]==N);
        if(isFinished) break;
        f(i,1,I,N) B[i]=0;
        f(i,1,I,N) B[ Max(i-A[i],1) ]++,B[ Min(i+A[i],N)+1 ]--;
        f(i,1,I,N) A[i]=A[i-1]+B[i];
    }

    f(i,1,I,N) print(A[i]),print(' ');
    output();
    return 0;
}

Measured memory_bytes: 6148
#include<bits/stdc++.h>
#define fr(i,j,n)   for(int i=j;i<n;i++)
#define pb          push_back
#define rf(i,j,p)   for(int i=p;i>=j;i--)
#define vi          vector<int>
#define vll         vector<long long>
#define ll          long long
#define hmm         "\n"
#define sp          " "
#define srt(v)      sort(v.begin(), v.end());
#define down        cout<<hmm;
#define faaast      ios_base::sync_with_stdio(0);cin.tie(nullptr);
using namespace std;
int main()
{
 string s ; cin >> s ;  vi v ;
 fr(i,0,s.size())
 {
     if(s[i]=='W')v.pb(i+1);
 }
 ll sum=0;
 fr(i,0,v.size())
 {
     sum+=v[i];
 }
ll n = v.size();
sum-=n*(n+1)/2;
cout<<sum<<hmm;
// return main();
}

Measured memory_bytes: 4440
#include <iostream>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

long long f(long long a) {
    long long t, s;

    if (((a+1)/2)%2 == 0) t = 0;
    else t = 1;
   
    if ((a+1)%2 == 0) s = 0;
    else s = a;

    return t ^ s;
}


int main() {
    long long a, b; cin >> a >> b;
    cout << (f(a-1) ^ f(b)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int maxn=10000;
int a[maxn];
int b[105][105];

int main()
{
    int h,w,n;
    cin>>h>>w>>n;
    for(int i=1;i<=n;++i)
        scanf("%d",&a[i]);
        int stemp=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[stemp]>0) {b[i][j]=stemp;--a[stemp];}
                   else if(a[stemp]==0) {++stemp;b[i][j]=stemp;--a[stemp];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[stemp]>0)
                    {b[i][j]=stemp;--a[stemp];}
                    else if(a[stemp]==0)
                        {++stemp;b[i][j]=stemp;--a[stemp];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) cout<<b[i][j]<<" ";
                else cout<<b[i][j]<<endl;
            }
        }
    return 0;
}

Measured memory_bytes: 384
a = input()
n = len(a)
ans =  n * (n-1) // 2
char = [0 for i in range(26)]
for i in range(n):
    char[ord(a[i])-ord('a')] += 1
for i in range(26):
    ans -= (char[i] * (char[i]-1))//2
print(ans+1)



Measured memory_bytes: 3500
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    vec = [0] * (N + 1)
    vec[0] = 2
    vec[1] = 1

    for i in range(2, N + 1):
        vec[i] = vec[i - 1] + vec[i - 2]

    print(vec[N])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [10**10] * N
    dp[0] = 0
    for i in range(1, N):
        for j in range(1, K+1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i-j] + abs(H[i] - H[i-j]))
    print(dp[N-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 52444
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    S=sum(A)
    oddS=sum(A[i] for i in range(1,n,2))
    ans=[0]*n
    ans[0]=S-2*oddS
    for i in range(n-1):
        ans[i+1]=2*A[i]-ans[i]
    print(*ans)
resolve()

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 1000006;

i64 n, m;
i64 a[MAXN];
i64 ps[MAXN];

i64 bin(i64 i, i64 l, i64 r, i64 v) {
    if (l == r) {
        return l;
    }

    if (l + 1 == r) {
        if (a[i] + a[l + 1] >= v) {
            return l + 1;
        }
        else {
            return l;
        }
    }

    i64 t = (l + r) / 2;
    if (a[i] + a[t] >= v) {
        return bin(i, t, r, v);
    }
    else {
        return bin(i, l, t, v);
    }
}

i64 cnt(i64 v) {
    i64 R = 0;
    for (i64 i = 1; i <= n; i++) {
        R += bin(i, 0, n, v);
    }
    return R;
}

i64 sum(i64 v) {
    i64 R = 0;
    for (i64 i = 1; i <= n; i++) {
        i64 j = bin(i, 0, n, v);
        R += a[i] * j + ps[j];
    }
    return R;
}

i64 binr(i64 l, i64 r) {
    if (l == r) {
        return l;
    }
    if (l + 1 == r) {
        if (cnt(l + 1) >= m) {
            return l + 1;
        }
        else {
            return l;
        }
        
    }

    i64 t = (l + r) / 2;
    if (cnt(t) >= m) {
        return binr(t, r);
    }
    else {
        return binr(l, t);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m;

    for (i64 i = 1; i <= n; i++) {
        cin >> a[i];
    }

    sort(a + 1, a + n + 1, greater<i64>());

    for (i64 i = 1; i <= n; i++) {
        ps[i] = ps[i - 1] + a[i];
    }

    i64 v = binr(a[n] + a[n], a[1] + a[1]);
    i64 R = sum(v) - (cnt(v) - m) * v;

    cout << R << endl;

    return 0;
}

Measured memory_bytes: 5248
N = int(input())
a = list(map(int, input().split()))

ans = 0
count = [0] * (10 ** 5 + 1)

for i in range(N):
  if a[i] <= 10 ** 5:
    count[a[i]] += 1
    ans += 1
    if count[a[i]] == a[i]:
      ans -= a[i]
  else:
    ans += 1

print(ans)


Measured memory_bytes: 14692
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    string S;
    cin >> S;
    unordered_set<char> char_set;
    for (auto s : S) {
        char_set.insert(s);
    }
    
    int ans = INF;
    for (auto& s : char_set) {
        int cnt = 0;
        string old_S = S;
        while (1) {
            bool is_all_same = true;
            rep(i, old_S.size()) {
                if (old_S[i] != s) {
                    is_all_same = false;
                    break;
                }
            }

            if (is_all_same == true)
                break;

            cnt++;

            //string new_S;
            int pop_idx;
            for (int i = old_S.size() - 1; i >= 0; i--) {
                if (old_S[i] != s) {
                    pop_idx = i;
                    break;
                }
            }
            string new_S;
            rep(i, old_S.size()) {
                if (i == pop_idx) continue;
                if (i + 1 < old_S.size() && old_S[i + 1] == s)
                    new_S += s;
                else
                    new_S += old_S[i];

            }
            old_S = new_S;
        }
        ans = min(ans, cnt);

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

Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := nextInt(sc)
	b := nextInt(sc)

	fmt.Printf("%d %d %6f", a/b, a%b, float64(a)/float64(b))
}



Measured memory_bytes: 1108
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll wt[109];
ll price[109];
ll dp[101][100001];
ll knapsack(ll n,ll w)
{
    if(n==0 or w==0)
    {
        return 0;
    }
    ll inc=0,exc=0;
    if(w>=wt[n-1])
    {
        inc=price[n-1]+knapsack(n-1,w-wt[n-1]);
    }
    exc=knapsack(n-1,w);
    return max(inc,exc);
} 
ll topdown(ll n,ll w)
{
    if(n==0 or w==0)
    {
        dp[n][w]=0;
        return 0;
    }
    if(dp[n][w]!=-1)
    {
        return dp[n][w];
    }
    ll inc=0,exc=0;
    if(w>=wt[n-1])
    {
        inc=price[n-1]+topdown(n-1,w-wt[n-1]);
    }
    exc=0+topdown(n-1,w);
    dp[n][w]=max(inc,exc);
    return dp[n][w];
}
int main()
{
    
    memset(dp,-1,sizeof dp);
    ll n,w;
    cin>>n>>w;
    for(ll i=0;i<n;i++)
    {
        cin>>wt[i]>>price[i];
    }
    cout<<topdown(n,w)<<endl;
    return 0;
}

Measured memory_bytes: 82472
#include <stdio.h>
int main()
{
	int P=0, Q=0, R=0;
	int i = 0, j = 0;
	scanf("%d", &P);
	scanf("%d", &Q);
	scanf("%d", &R);
	if (P >= Q&&P >= R)
	{
		printf("%d", R + Q);
	}
	else if ( Q>= P&&Q >= R)
	{
		printf("%d", P + R);
	}
	else if (R >= Q&&R >= P)
	{
		printf("%d", Q + P);
	}
}

Measured memory_bytes: 128
n = gets.to_i

cities = []

n.times do
  x, y = gets.split.map(&:to_i) 
  cities << [x, y]
end

routes = cities.permutation.to_a
sum = 0.0
routes.each do |route|
  pos = route[0]
  route[1..-1].each do |to|
    diff = Math.sqrt(
      (pos[0] - to[0])**2 +
      (pos[1] - to[1])**2
    )
    pos = to
    sum += diff
  end
end

puts sum / routes.size

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

int dp[3001][3001];

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 1; i <= s.length(); i++) {
        for (int j = 1; j <= t.length(); j++) {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = max(dp[i - 1][j - 1] + 1, max(dp[i - 1][j], dp[i][j - 1]));
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    int i = s.length(), j = t.length();
    string ans = "";
    while (dp[i][j] != 0) {
        while(dp[i][j] == dp[i-1][j]) {
            i--;
        }
        while(dp[i][j] == dp[i][j-1]) {
            j--;
        }
        i--;
        j--;
        ans.push_back(s[i]);
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 38784
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int k,a,b;
    cin>>k>>a>>b;
    ll ans=1;
    if(b-a<2){
        ans+=k;
    }else{
        while(k){
            if(ans>=a and k>=2){
                ans+=b-a;
                k-=2;
            }else{
                ans++;
                k--;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int n,a[110];
    cin >> n;
    rep(i,n) cin >> a[i];

    int min = a[0];
    int max = a[0];
    rep(i,n){
        if(min>a[i]){
            min = a[i];
        }
        if(max<a[i]){
            max = a[i];
        }
    }

    int ans = max - min;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    ll x;
    cin >> x;
    x--;
    if (x % 11 <= 5) {
        cout << 2 * (x / 11) + 1;
    }
    else {
        cout << 2 * (x / 11) + 2;
    }
    return 0;
}

Measured memory_bytes: 256