akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

ll mypow(ll n, ll k) {
	ll res = 1;
	n %= DIV;
	while (k > 0) {
		if (k % 2) {
			res *= n;
			res %= DIV;
		}
		k /= 2;
		n *= n;
		n %= DIV;
	}
	return res;
}

ll mmod(ll a, ll b) {
	if (a < 0)a += DIV;
	if (b < 0)b += DIV;
	return (a * b) % DIV;
}

int main() {
	ll N, M; cin >> N >> M;
	vector<ll> f(M + 1), invf(M + 1);
	f[0] = 1, invf[0] = 1;
	for (int i = 1; i <= M; i++) {
		f[i] = (f[i - 1] * i) % DIV;
		invf[i] = mypow(f[i], DIV - 2);
	}
	//cout << mypow(2, 5) << endl;
	ll ans = 0, s = 1;
	for (int k = 0; k <= N; k++) {
		ll temp1 = mmod(mmod(f[N], invf[k]) , invf[N - k]);
		ll temp2 = mmod(f[M - k], invf[M - N]);
		temp2 = mmod(temp2, mmod(f[M], invf[M - N]));
		temp2 = mmod(temp1,temp2);
		//cout << "temp2=" << temp2 << endl;
		ans += s * temp2 + DIV;
		ans %= DIV;
		s *= -1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 11160
N,K = map(int,input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)


s = Base_10_to_n(N,K)
print(len(s))



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

using namespace std;
using ll = long long;

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

  string s, t;
  cin >> s >> t;

  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)

#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld\n",a)

#define stll(a) stoll(a,nullptr,10)
#define all(a) a.begin(),a.end()
#define PII pair<ll,ll>
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define EL printf("\n")
#define ff first
#define ss second
#define rev(a) reverse(all(a))


#define mem(ar,val) memset(ar,val,sizeof(ar))
#define ssort(ar) sort(ar.begin(),ar.end())
#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)

#define bug1(a) cerr<<"test "<<a<<endl;
#define bug2(a,b) cerr<<"test "<<a<<" "<<b<<endl;
#define bug3(a,b,c) cerr<<"test "<<a<<" "<<b<<" "<<c<<endl;
#define bug4(a,b,c,d) cerr<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define fout freopen("output.txt","w",stdout)
#define fin  freopen("input.txt","r",stdin)

/// unordered_map<int,int>mp;
/// mp.reserve(1024);
/// mp.max_load_factor(0.25);

/// pbds
/// *find_by_order(k) - return k th largest element.. 0 based
/// order_of_key(k) - number of items strictly smaller than k

///  priority_queue <ll, vector<ll>, greater<ll> >

/*
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
*/

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;



int main()
{
    ll n,a,b,tt;
    PII x,p,q,r;
    cin>>n;
    cin>>x.ff>>x.ss;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        tt = max(x.ff/a,x.ss/b);
        if(a*tt <x.ff || b*tt<x.ss)
            tt++;
        x.ff=a*tt,x.ss=b*tt;
    }
    cout<<x.ff+x.ss<<endl;
}













Measured memory_bytes: 3604
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
using namespace std;



int main(){
  ll r;
  ll ANS;
  cin>>r;
  ANS=pow(r,2);
  cout<<ANS<<endl;
  return 0;
}



Measured memory_bytes: 256
l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
x = 0
m = k-int(j[-1])+int(j[0])
for i in range(n-1):
  d = int(j[i+1]) - int(j[i])
  x = max(x,d)
x = max(x,m)
dt = k - int(x)
print(dt)


Measured memory_bytes: 18508
def b():
	from math import floor,ceil
	N = int(input())
	bef = N / 1.08
	if int(floor(bef) * 1.08) == N:
		print(floor(bef))
	elif int(ceil(bef) * 1.08) == N:
		print(ceil(bef))
	else:
		print(":(")
b()

Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int main(){
    string a;
    string b;
    cin >> a >> b;
    if(a == b.substr(0, a.length())){
        if(b.length() == a.length() + 1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3028
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 100000, stdin), p1==p2)?EOF:*p1++)
char buf[100000],*p1,*p2;
inline int rd() {
    int x = 0; char ch = nc();
    while(!isdigit(ch)) ch = nc();
    while(isdigit(ch)) x = (x<<1) + (x<<3) + (ch^48), ch = nc();
    return x;
}
ll n;ll m=200000;
ll t[200010];
void add(ll x,ll val){
	for(;x<=m;x+=x&-x) t[x]+=val;
}
ll query(ll x){
	ll re=0;
	for(;x>0;x-=x&-x) re+=t[x];
	return re;
}
struct node{
	ll val,num;
}a[100010];
ll num[100010];
bool cmp1(node l,node r) {return l.val<r.val; }
bool cmp2(node l,node r) {return l.num<r.num; }
ll x[100010];ll lim;
bool check(ll val) {
	ll i;ll sum=0,re=0;memset(t, 0, sizeof t);
	for(i=1;i<=n;i++) {
		if(a[i].val<val) x[i]=-1;
		else x[i]=1;
	}
	add(100000,1);
	for(i=1;i<=n;i++) {
		sum+=x[i];
		re+=query(sum+100000);
		add(sum+100000,1);
	}
	return re>=(lim/2+lim%2);
}
int main() {
	ll i;
	n=rd();lim=n*(n+1)/2;
	for(i=1;i<=n;i++) a[i].val=rd(),a[i].num=i;
	sort(a+1,a+n+1,cmp1);
	for(i=1;i<=n;i++) num[i]=a[i].val;
	sort(a+1,a+n+1,cmp2);
	ll l=1,r=n,mid;
	while(l<r){
		mid=(l+r)>>1;mid++;
		if(check(num[mid])) l=mid;
		else r=mid-1;
	}
	printf("%lld\n",num[l]);
} 


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

using namespace std;

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> pos(26);
  for (int i = 0; i < n; i++) {
    int idx = s[i] - 'a';
    pos[idx].insert(i);
  }
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int t;
      char c;
      cin >> t >> c;
      t--;
      int idx = c - 'a';
      int pre = s[t] - 'a';
      s[t] = c;
      pos[pre].erase(t);
      pos[idx].insert(t);
      continue;
    }
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    int ret = 0;
    for (int i = 0; i < 26; i++) {
      auto itr = pos[i].lower_bound(l);
      if (itr == pos[i].end()) continue;
      if (*itr <= r) ret++;
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 24324
S = input()
T = input()

n = len(S)
def same(i, j):
    for k in range(0, n):
        if(S[(i + k)%n] != T[(j + k)%n]):
            return 0
    return 1


ans = 0
for i in range(0, n):
    ans |= same(i, 0)


if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define decimal fixed << setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int r = 0, x = 0;
    int now = 0, ans = 0;
    while(s[r] == '1' && r<n){
        now++;
        r++;
    }
    int l = 0;
    while(l < n){
        if(x >= k){
            while(s[l] == '1' && l < n){
                now--;
                l++;
            }
            while(s[l] == '0' && l < n){
                now--;
                l++;
            }
            x--;
            continue;
        }
        x++;
        while(s[r] == '0' && r<n){
            now++;
            r++;
        }
        while(s[r] == '1' && r<n){
            now++;
            r++;
        }
        // cout << l << " " << r << endl;
        ans = max(ans, now);
    }
    ans = max(ans, now);
    cout << ans << endl;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,x;
  cin>>a>>b>>x;
  if(a>0)cout<<(b)/x-(a-1)/x<<endl;
  else cout<<b/x+1<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
//#include <string>
//#include <math.h>
//#include <vector>

using namespace std;

int main() {
  int N;
  long int *A;

  int i;
  long int sum=0;
  
  cin >> N; 


  A = new long int[3*N];
  
  for(i=0; i<3*N; i++){
    scanf("%ld",&A[i]);
  }

  //  nth_element(A, A + N-1, A+3*N);  
  sort(A,A+3*N);  
  for(i=3*N-2; i>= N; i -=2){    
    sum += A[i];
  }  
  
  cout << sum;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>

int main() {
    int N, ans{0}, rec{0}, cnt{0}, temp{0};
    std::cin >> N;
    
    for (int i=1; i<=N; ++i) {
        cnt = 0;
        temp = i;
        while (temp / 2 != 0) {
            cnt++;
            temp /= 2;
        }
        if (cnt > rec) {
            rec = cnt;
            ans = i;
        }
    }
    std::cout << (ans!=0 ? ans : 1)  << std::endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main( void )
{
	long long n, m, i;
	while(cin >> n) {
		m = 3; i = 1;
		while(n > m) {
			++i;
			m *= 3;
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  ll n, m;
  cin >> n >> m;
  vector<pii> a(n);
  rep(i, n) {
    cin >> a[i].first >> a[i].second;
  }

  sort(all(a));

  ll ans = 0;

  rep(i, n) { 
    if (m > a[i].second) {
      ans += (ll)a[i].first * a[i].second;
      m -= a[i].second;
    } else {
      ans += (ll)a[i].first * m;
      m = 0;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
//B
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int k;
		cin>>k;
		n-=k;
	}
	if(n<0)cout<<-1<<endl;
	else cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <stdlib.h>

using namespace std; 

int main(void){
	long int a[100];
	int n, i, j, max, tmp;

	max = -1;
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	for(i = 0; i < n - 1; i++){
		for(j = i + 1; j < n; j++){
			tmp = abs(a[i] - a[j]);
			if(tmp > max){
				max = tmp;
			}
		}
	}
	cout << max << endl;

	return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> cnt(N);

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

    bool ok = true;
    if (N % 2 == 0){
        if (cnt[0] != 0) {
            ok = false;
        }
        for (int i = 1; i < N; i += 2){
            if (cnt[i] != 2){
                ok = false;
                break;
            }
        }
    } else {
        if (cnt[0] != 1) {
            ok = false;
        }
        for (int i = 2; i < N; i += 2) {
            if (cnt[i] != 2) {
                ok = false;
                break;
            }
        }
    }

    ll ans;
    if (ok) {
        ans = 1;
        for (int i = 0; i < N/2; i++){
            ans *= 2;
            ans %= MOD;
        }
    } else {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
int n,m;
bool check(int a,vint &v){
    int t=0;
    int cnt=0;
    rep(i,v.size()){
        if(a<v[i]) return false;
        if(t+v[i]>a){
            cnt++;
            t=v[i];
        }
        else{
            t+=v[i];
        }
    }
    if(cnt+1<=m) return true;
    return false;
}


void mainmain(){
    // int m,n;
    while(cin>>m>>n){
        if(m==0) return;
        vint v(n);
        rep(i,n) cin>>v[i];
        int l=0;
        int r=INF;
        while(r-l>1){
            int mid=(r+l)/2;
            if(check(mid,v)) r=mid;
            else l=mid;
        }
        cout<<r<<endl;
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1192
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
//import java.io.*;
//import java.util.stream.IntStream;



public class Main {

    static class Node{
        Node parent = null;
        Node leftChild = null;
        Node rightChild = null;
        Integer key = null;

        public Node(){};
        public Node(int key){
            this.key = key;
        };
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
        // int n = Integer.parseInt(br.readLine());
        Node root = new Node();

        int n = Integer.parseInt(sc.nextLine());
        for(int i=0; i<n;i++){
            String command = sc.nextLine();
            if(command.charAt(0) == 'i'){
                int key = Integer.parseInt(command.split(" ")[1]);
                insert(root, key);
            }else{
                print(root);
            }

        }

    }

    public static void insert(Node root, int key){
        // xとxParentを木の下に移動していく
        Node x = root;
        Node y = new Node(key);
        Node xParent = null;

        if(x.key == null){
            x.key = y.key; //x = y x.keyの値が変更できないことに注意。xに入っているのはあくまでアドレス値
            return;
        }
        
        while(x != null){
            xParent = x;
            if(x.key < y.key){
                x = x.rightChild;
            } else {
                x = x.leftChild;
            }
        }

        y.parent = xParent;
        if(xParent == null){
            x = y;
        }else if(xParent.key<y.key){
            xParent.rightChild = y;
        }else if(xParent.key>y.key){
            xParent.leftChild = y;
        }

    }

    public static void print(Node root){
        List<Integer> preList = new ArrayList<>();
        List<Integer> inList = new ArrayList<>();

        preOrder(root, preList);
        inOrder(root, inList);

        inList.stream().forEach((val)->{System.out.print(" " + val);});
        System.out.println();
        preList.stream().forEach((val)->{System.out.print(" " + val);});
        System.out.println();
    }
    public static void preOrder(Node root, List<Integer> preList){
        Node x = root;
        if(x == null){
            return;
        }
        preList.add(x.key);
        preOrder(x.leftChild, preList);
        preOrder(x.rightChild, preList);
    }
    public static void inOrder(Node root, List<Integer> inList){
        Node x = root;
        if(x == null){
            return;
        }
        inOrder(x.leftChild, inList);
        inList.add(x.key);
        inOrder(x.rightChild, inList);
    }
}





Measured memory_bytes: 575900
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int n;


int main(){
  cin>>n;
  int tmp = 0;
  int ans = 0;
  for(int i=1;i<=n;i++){
    ans++;
    tmp+=i;
    if(tmp >= n) break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
//ll arr[1000002];
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
ll ans=0;
void func(ll arr[],ll k,ll p[],vector<ll>v[],ll n,ll m)
{
    ll i,j;
    if(k==n+1)
    {
        ll b[m+1]={0},f=0;
        for(i=1;i<=n;i++)
        {
            if(arr[i]==1)
            {
                for(auto u:v[i])
                    b[u]++;
            }
        }
        for(i=1;i<=m;i++)
        {
            if(p[i]==1 && b[i]%2==0)
                return;
             if(p[i]==0 && b[i]%2==1)
                return;
        }
        ans++;
        return;
    }
    arr[k]=0;
    func(arr,k+1,p,v,n,m);
    arr[k]=1;
    func(arr,k+1,p,v,n,m);
    return;
}
int main()
{
  ll n,m,i,k,s,j;
  cin>>n>>m;
  vector<ll>v[n+1];
  for(i=1;i<=m;i++)
  {
      cin>>k;
      for(j=0;j<k;j++)
      {
          cin>>s;
          v[s].pb(i);
      }
  }
  ll p[m+1];
  for(i=1;i<=m;i++)
    cin>>p[i];
    ll arr[n+1];
    func(arr,1,p,v,n,m);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
const int N = 100005;
 
int n, sz[N];
long long res, f[N];
vector<ii> G[N];
 
void dfs(int u, int p) {
    sz[u] = 1;
    for (auto v : G[u]) {
        if (v.first == p) continue;
        dfs(v.first, u), sz[u] += sz[v.first];
    }
}
 
int find(int u, int p) {
    for (auto v : G[u]) {
        if (v.first == p) continue;
        if (sz[v.first] * 2 >= n) return find(v.first, u);
    }
    return u;
}
 
void reDfs(int u, int p) {
    res += f[u] * 2, sz[u] = 1;
    for (auto v : G[u]) {
        if (v.first == p) continue;
        f[v.first] = f[u] + v.second, sz[u] += sz[v.first];
        reDfs(v.first, u);
    }
}
 
int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i < n; ++i) {
        int u, v, w; cin >> u >> v >> w;
        G[u].push_back(ii(v, w));
        G[v].push_back(ii(u, w));
    }
    dfs(1, 1);
    int r = find(1, 1);
    reDfs(r, r), dfs(r, r);
    long long mn = 1e18;
    for (auto i : G[r]) {
        if (sz[i.first] * 2 == n) {
            cout << res - f[i.first]; return 0;
        }
        mn = min(mn, f[i.first]);
    }
    cout << res - mn;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod= 1e9+7;

int main(){
  int N,M,C,b[20],a[20][20];
  cin>>N>>M>>C;
  for (int i(0);i<M;i++) cin>>b[i];
  for (int i(0);i<N;i++) 
    for (int j(0);j<M;j++) 
      cin>>a[i][j];
  int cnt(0);
  for (int i(0);i<N;i++){
    int sum(0);
    for (int j(0);j<M;j++){
      sum+=a[i][j]*b[j];
    }
    sum+=C;
    cerr << sum << " ";
    if (sum>0) cnt+=1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
x = []
n.times do
  name, time = gets.chomp.split
  x << [name, time.to_i]
end
t = 0
while x.length > 0
  y = x.shift
  if y[1] <= q
    t += y[1]
    puts "#{y[0]} #{t}"
  else
    t += q
    y[1] -= q
    x << y
  end
end


Measured memory_bytes: 11684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int INF = 0x3f3f3f3f;
int a[maxn];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int cur = INF, mx = -1, cnt = 0;
	for(int i = 0; i < n; i++) {
		if(a[i] <= cur) {
			cur = a[i];
			cnt++;
		}
		else {
//			cout << cnt << "-";
			mx = max(mx, cnt);
			cnt = 1;
			cur = a[i];
		}	
	}
	mx = max(mx, cnt);
	cout << mx - 1 << endl;
	
}

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

int main()
{
    int w, h, x, y, r;

    cin >> w >> h
        >> x >> y >> r;

    if (x >= r && x <= w - r && y >= r && y <= h -r)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3108
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int ans=0;
string s;
cin>>s;
int n=s.size();
for(int i=1;i<n/2;i++){
    bool ok=true;
    for(int j=0;j<i;j++){
        if(s[j]!=s[j+i])ok=false;
    }
    if(ok)chmax(ans,i*2);
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, m;
	string s;
	cin >> n >> m;
	rep(i, n) {
		cin >> s;
		cout << s << endl << s << endl;
	}

}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int A = 0, B = 0, C = 0;
    if(x > y){
        A = y * c * 2 + (x - y) * a;
    }else{
        A = x * c * 2 + (y - x) * b;
    }

    B = max(x, y) * c * 2;
    C = a * x + b * y;

    int ans = min(A, min(B, C));
    cout << ans << endl;


    return 0;
}

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


class Input():
    def __init__(self):
        self.line = input()

    def number(self):
        return int(self.line)

    def numbers(self):
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strings(self):
        return self.line.split(' ')


def main():
    ipt = Input()
    ab = ipt.numbers()
    a = ab[0]
    b = ab[1]

    if a < 10 and b < 10:
        print(a*b)
    else:
        print('-1')


main()


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cmath>
#include <list>
#include <vector>
#include <tuple>
using namespace std;
//#define FILENAME "./F/in/b04"
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

#define MOD 1000000007

int r;

int main(int argc, char *argv[]) {

#ifdef FILENAME
  ifstream file(FILENAME);
  cin.rdbuf(file.rdbuf());
#endif

  cin >> r;
  cout << 3*r*r << endl;
  
  
  return 0;
}


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

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
	operator int() const noexcept { return to; }
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
void warshallFloyd(Matrix<T> &G,int n){
	for(int k = 0;k < n;k++){
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
			}
		}
	}
}

int n,m,l,s,t,v[20],e[20];
int dp[1 << 17][20];
Matrix<int> dist(310,vector<int>(310));

void solve(){
	s--;
	const int INF = 1e+11;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++) dist[i][j] = INF;
		dist[i][i] = 0;
	}
	for(int i = 0;i < m;i++){
		int a,b,c;
		cin >> a >> b >> c; a--;b--;
		dist[a][b] = dist[b][a] = c;
	}
	warshallFloyd(dist,n);
	v[0] = s; e[0] = 0;
	for(int i = 1;i <= l;i++){
		cin >> v[i] >> e[i]; v[i]--;
	}
	l++;
	for(int i = 0;i < (1 << l);i++){
		for(int j = 0;j < l;j++) dp[i][j] = INF;
	}
	dp[0][0] = 0;
	for(int i = 0;i < (1 << l);i++){
		for(int j = 0;j < l;j++){
			for(int k = 0;k < l;k++){
				if(i >> k & 1) continue;
				chmin(dp[i | (1 << k)][k],dp[i][j] + dist[v[j]][v[k]] + e[k]);
			}
		}
	}
	int ans = 0;
	for(int i = 0;i < (1 << l);i++){
		if(dp[i][0] <= t) chmax(ans,(int)__builtin_popcountll(i) - 1);
	}
	cout << ans << endl;
}

signed main(){
	while(cin >> n >> m >> l >> s >> t,n) solve();
}



Measured memory_bytes: 23956
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int N;
	cin >> N;
    vector<int> a(N);
    int sm = 0;
    rep(i,N) {
        cin >> a[i];
        sm += a[i];
    }
    float avg = (float) sm / N;
    float mn = 100;
    vector<float> dif(N);
    rep(i,N) {
        dif[i] = (float) abs(a[i] - avg);
        mn = min(mn, dif[i]);
    } 
    int ans;
    rep(i,N) {
        if (dif[i] == mn) {
            ans = i;
            break;
        }
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long n, m;
    cin >> n >> m;
    long h[n+1];
    long isGood[n+1];
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        isGood[i] = true;
    }

    for (int j = 0; j < m; ++j) {
        int a, b;
        cin >> a >> b;
        if(h[a-1] > h[b-1]) {
            isGood[b-1] = false;
        }else if(h[a-1] < h[b-1]) {
            isGood[a-1] = false;
        }else{
            isGood[a-1] = false;
            isGood[b-1] = false;
        }
    }

    int c = 0;
    for (int k = 0; k < n; ++k) {
        if(isGood[k]){
            c++;
        }
    }

    cout << c << endl;



    return 0;
}


Measured memory_bytes: 4752
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int K;
	int N;
	cin >> K >> N;
	vector<int> A(N);
	int total = 0;
	
	for(int i = 0;i<N;i++){
		std::cin >> A[i];
	}
	total = A[0]+K-A[N-1];
	
	for(int i = 1;i<N;i++){
		if(total<A[i]-A[i-1]){
			total = A[i]-A[i-1];
			
		}
	}
	std::cout << K-total  <<  std::endl;
  
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL c[200005][5],n,k,ans;
void pre(){
	c[1][1]=1,c[1][0]=1;
	for (int i=2;i<=200001;i++)
	{
		c[i][0]=1;
		for (int j=1;j<=3;j++)
		c[i][j]=c[i-1][j]+c[i-1][j-1];
	}
}
int main(){
	pre();
	cin>>n>>k;
	if (!k)
	{
		puts(0);
		return 0;
	}
	LL s1=n/k;
	ans+=c[s1][1]+c[s1][2]*6+c[s1][3]*6;
	if (k&1) 
	{
		cout<<ans<<"\n";	
	}
	else {
		LL s2=(n+k/2)/k;
		ans+=c[s2][1]+c[s2][2]*6+c[s2][3]*6;
		cout<<ans<<"\n";
	}
	return 0;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  lol n, a, b;
  cin >> n;
  for(lol i = 1;i * i <= n;i ++){
    if(n % i == 0){
      a = i;
      b = n / i;
    }
  }
  int ans = max(a, b), d = 0;
  while(ans > 0){
    d ++;
    ans /= 10;
  }
  cout << d << '\n';
  return 0;
}


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

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

    int b[n];
    for (int i = 0; i < n; i++)
    {
        b[i] = (int)(str[i] - '0');
    }
    
    
    int count = 0;
    int index;
    bool c[1000];
    for (int i = 0; i < 1000; i++)
    {
        c[i] = false;
    }
    

    for (int i1 = 0; i1 < 10; i1++)
    {
        for (int i2 = 0; i2 < 10; i2++)
        {
            for (int i3 = 0; i3 < 10; i3++)
            {
                index = i1*100 + i2*10 + i3;
                //各桁を調べる
                //1
                for (int j1 = 0; j1 < n-2; j1++)
                {
                    if(b[j1] == i1)
                    {
                        //2
                        for (int j2 = j1+1; j2 < n-1; j2++)
                        {
                            if (b[j2] == i2)
                            {
                                //3
                                for (int j3 = j2+1; j3 < n; j3++)
                                {
                                    if (b[j3] == i3)
                                    {
                                        c[index] = true;
                                        break;
                                    }
                                    
                                }
                                break;
                            }
                            
                            
                        }
                        break;
                    }
                    

                }
                
            }
        }
    }
    for (int i = 0; i < 1000; i++)
    {
        if(c[i])count++;

    }

    
    cout << count << endl;


    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
__int128 x, y;
void exgcd(ll a, ll b){
	if(b == 0){
		x = 1, y = 0;
		return;
	}
	exgcd(b, a % b);
	ll tmp = x; x = y, y = tmp - (__int128)(a / b) * y;
}
ll n;
int bit;
std::vector<std::pair<ll, int> > d;
ll val[100];
ll ans = 1e18;
int main(){
	std::scanf("%lld", &n); n *= 2;
	if(n == 2){
		std::puts("1");
		return 0;
	}
	ll r(n);
	for(int i = 2; (ll)i * i <= r; ++i)
		if(r % i == 0){
			int cnt = 0;
			while(r % i == 0) r /= i, ++cnt;
			d.push_back({i, cnt});
		}
	if(r != 1) d.push_back({r, 1});
	int bit = d.size();
	for(int i = 0; i < bit; ++i){
		val[i] = 1;
		for(int j = 0; j < d[i].second; ++j) val[i] *= d[i].first;
	}
	for(int S = 1; S < (1 << bit); ++S){
		ll a = 1, b = 1;
		for(int j = 0; j < bit; ++j)
			if(S & (1 << j)) a *= val[j];
			else b *= val[j];
		exgcd(a, b);
		x = (x % b + b) % b, y = (x % a + a) % a;
		if(x * a == 1) x += b;
	//	std::printf("%lld %lld %lld %lld\n", a, b, (ll)x, (ll)y);
		x *= a; if(x && x - 1 < ans) ans = x - 1;
		std::swap(a, b);
		exgcd(a, b);
		x = (x % b + b) % b, y = (x % a + a) % a;
		if(x * a == 1) x += b;
	//	std::printf("%lld %lld %lld %lld\n", a, b, (ll)x, (ll)y);
		x *= a; if(x && x - 1 < ans) ans = x - 1;
	}
	std::printf("%lld\n", ans);
}

Measured memory_bytes: 3800
//Twitter@KonoLv1 2020年春卒で現在就職活動中！
 
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
 
int main(void){
    int i,j;            //  ループ文に使用
    int x,y,z;
    int count1,count2,count;   //  カウント用に使用
    int box[256] = {};
    char s[200001] = {};        //  文字列
    char s2[200001] = {};        //  文字列
    int a,b,c;
    a = b = c = i = 0;
    int mode = 0;
    count = count1 = count2 = 0;
 
    //  入力処理
    
    scanf("%d",&a);

 
 
    //  計算処理
    

      for (i = 0; i < a; i++){
        for (j = 0; j < a; j++){
            for (z = 0; z < a; z++){
                count++;
            }
        }
    }

    //  出力処理
 
    printf("%d",count);
 
}

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

#define       pb                 push_back
#define       mx                 200005
#define       MOD                1000000007
#define 	  optimize           ios::sync_with_stdio(0);cin.tie(0);
#define 	  inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

typedef       long long int      ll;
typedef       vector<int> 	     vi;

int main()
{
    int n;
    double a, ans=0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> a;

        ans += (1.0/a);
    }

    cout << (1/ans) << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include<bits/stdc++.h>
using namespace std; 
  
int main() 
{ 
  
 	int n = 0;
  int m = 0;
     
  std::cin>>m;
  
  vector<int> vec(m+1);

  for(int i =1; i<m;i++){
    int a;
    cin>>a;
    vec[a]++;
  } 
  
  for(int i =1; i<=m;i++){
    cout<<vec[i]<<endl;
  }


  return 0; 
} 


Measured memory_bytes: 4060
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  if( s > "2019/04/30")
    cout << "TBD";
  else
  {
    cout << "Heisei";
  }
  

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
s = input()
s = s.split("/")
s[0]=int(s[0])
s[1]=int(s[1])
s[2]=int(s[2])
if s[0]<2019:
	print('Heisei')
elif s[0]==2019 and s[1]<4:
	print('Heisei')
elif s[0]==2019 and s[1]==4 and s[2]<=30:
	print('Heisei')
else:
	print('TBD')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    ll N;
    cin >> N;
    VL P(N);
    FOR(i, 0, N) cin >> P[i];

    ll m = P[0];
    ll ans = 1;
    for (int i = 1; i < N; i++){
        m = min(m, P[i]);
        if(P[i] <= m) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
/**
 *   Author: Praveen Ojha
 *   Created: 24 March 2019
 *   Time: 21:58:40
**/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long double ld;
typedef pair<int,int> pii;

vector <int> adj[100005];
int dp[100005];
//bool visited[100005];
int solve(int x){
	//visited[x]=true;
	if(adj[x].size()==0)
		return 0;
	if(dp[x]!=-1)
		return dp[x];
	int maxi=0;
	for(int i=0;i<(int)adj[x].size();i++){
		maxi=max(maxi,solve(adj[x][i]));
	}
	return dp[x]=1+maxi;
}
int32_t main(){__
	int n,m,x,y;
	memset(dp,-1,sizeof dp);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		adj[x].push_back(y);
	}
	for(int i=1;i<=n;i++){
		adj[0].push_back(i);
	}
	int ans=solve(0);
	cout<<ans-1<<"\n";
return 0;
}

Measured memory_bytes: 9336
let input () =
    let n  = int_of_string (read_line ())
    in let rec ds i result = if i >= n
        then result
        else let input = int_of_string (read_line ())
             in  ds (i+1) (input::result)
    in List.rev (ds 0 [])

let remove_duplicate (x::xs) = 
    let rec remove_duplicate' prev l = 
        match l with
        | []    -> []
        | x::xs -> if x == prev 
            then remove_duplicate' x xs
            else x :: (remove_duplicate' x xs)
    in x :: (remove_duplicate' x xs)

let _ = List.sort (Pervasives.compare) (input ())
     |> remove_duplicate
     |> List.length 
     |> print_int 
     |> print_newline

Measured memory_bytes: 384
N, C = map(int, input().split())
XV = [tuple(map(int, input().split())) for _ in range(N)]
XV.sort()

L = [0] * (N + 1)
S = 0
for i, (x, v) in enumerate(XV, start=1):
    S += v
    L[i] = max(L[i - 1], S - x)

R = [0] * (N + 1)
S = 0
for i, (x, v) in enumerate(XV[::-1], start=1):
    S += v
    R[i] = max(R[i - 1], S - (C - x))

ans = max(max(L), max(R))

S = 0
for i, (x, v) in enumerate(XV, start=1):
    S += v
    ans = max(ans, S - 2 * x + R[N - i])

S = 0
for i, (x, v) in enumerate(XV[::-1], start=1):
    S += v
    ans = max(ans, S - (C - x) * 2 + L[N - i])

print(ans)


Measured memory_bytes: 25284
#include <bits/stdc++.h>
using namespace std;
#define itn int

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

    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> cs(n);
    for (int i = 0; i < n; i++) cin >> cs[i];
    sort(cs.rbegin(), cs.rend());

    long long nax = 0;
    vector<int> ans(n), best;
    int idx = 0;
    function<void(int, int)> dfs = [&](int v, int p) {
        ans[v] = cs[idx++];
        for (int s : adj[v]) {
            if (s != p) {
                dfs(s, v);
            }
        }
    };

    auto start = chrono::system_clock::now();
    int i = 0;
    while (chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count() < 1800 && i < n) {
        dfs(i, -1);
        idx = 0;

        long long sum = 0;
        for (int a = 0; a < n; a++) {
            for (int b : adj[a]) {
                if (a < b) {
                    sum += min(ans[a], ans[b]);
                }
            }
        }

        if (sum > nax) {
            nax = sum;
            best = ans;
        }
    }
    cout << nax << endl;
    for (int a : best) cout << a << ' ';
}

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

int main(){
  int A, B;
  int ans=0;
  cin >> A >> B;
  
  for(int i=A;i<=B;i++){
  	if((i/10000)==(i%10)){ 
    	if(((i%100)/10)==((i/1000)%10)){
        	ans++;
        }
    }
  }
  
  cout << ans << endl;
}


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

int main(){
    int h, w; cin >> h >> w;
    char s[w+2][h+2];

    fill(s[0], s[w+2], '.');

    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            cin >> s[j][i];
            
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++){
            if(s[j][i] == '#' && s[j-1][i] != '#' && s[j+1][i] != '#' 
                && s[j][i-1] != '#' && s[j][i+1] != '#'){
                    put("No");
                    return 0;
                }
        }

    put("Yes");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int k=in(),s=in(),ans=0,i,j;
	for(i=0;i<=k;i++){
		for(j=0;j<=k;j++){
			int tmp=s-i-j;
			if(0<=tmp&&tmp<=k)ans++;
		}
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())

count_ab = 0
count_fb = 0
count_ea = 0
count_fbea = 0
for i in range(N):
    s = input()
    for j in range(len(s)-1):
        if s[j:j+2] == "AB":
            count_ab += 1
    if s[0] == "B" and s[len(s)-1] == "A":
        count_fbea += 1
    elif s[0] == "B":
        count_fb += 1
    elif s[len(s)-1] == "A":
        count_ea += 1

ans = count_ab
if count_fbea > 0:
    ans += count_fbea - 1
    if count_fb > 0:
        count_fb -= 1
        ans += 1
    if count_ea > 0:
        count_ea -= 1
        ans += 1
ans += min(count_fb, count_ea)
print(ans)

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

typedef long long ll;

#define sz(v) (int)v.size()

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
}


const int MAX = 2e5 + 100;
ll a[MAX], pre[MAX];

const int MOD = 1000000007;

int main() {
	PLAY();
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pre[i] = a[i];
	}

	for (int i = 1; i <= n; i++)
		pre[i] += pre[i - 1];

	ll res = 0;
	for (int i = 1; i <= n; i++) {
		ll sum = pre[n] - pre[i];
		ll x = ((sum % MOD) * (a[i] % MOD)) % MOD;
		res = (res% MOD + x % MOD) % MOD;
	}

	cout << res % MOD << endl;

	return 0;
}

Measured memory_bytes: 6772
#include <iostream>
#define MAX 301

using namespace std;

int dp[MAX];

void Make_dp(void){

  dp[0] = 1;

  for( int i = 1 ; i <= 17 ; i++ ){
    for( int j = 0 ; j < MAX ; j++ ){
      dp[i*i + j] += dp[j];
    }
  }

}

int main(void){

  Make_dp();

  int n;
  while( cin >> n , n )
    cout << dp[n] << endl;

  return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int N;
    cin >> N;
    int result = 0;
    REP(i, N) {
        int a;
        cin >> a;
        if (i % 2 == 0 && a % 2 == 1)
            ++result;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3652